Top 20 Basic C Programming VIVA Questions and Answers
🌐 Dive into the Heart of C Programming: Uncover the Top 20 Basic VIVA Questions and Expert Answers! 💡
Prepare to showcase your C programming prowess with our curated list of the Top 20 Basic C Programming VIVA Questions and Answers. Whether you're a student gearing up for exams or a professional looking to refresh your knowledge, this comprehensive guide is tailored to enhance your understanding and boost your confidence during VIVA sessions.
Questions
What is the purpose of the
registerkeyword in C?- The
registerkeyword suggests to the compiler that a variable is likely to be heavily used and should be stored in a CPU register if possible. However, modern compilers often optimize this automatically, making the use ofregisterless impactful.
- The
Explain the concept of typecasting in C.
- Typecasting involves converting a variable from one data type to another. For example,
(float) 5performs typecasting to a float.
- Typecasting involves converting a variable from one data type to another. For example,
What is the role of the
constkeyword in a function parameter list?- In a function parameter list, the
constkeyword is used to indicate that the parameter is treated as a constant and cannot be modified within the function.
- In a function parameter list, the
Discuss the purpose of the
#ifdefand#ifndefdirectives in C.#ifdefchecks if a macro is defined, while#ifndefchecks if a macro is not defined. They are commonly used for conditional compilation.
What is the purpose of the
enumkeyword in C?- The
enumkeyword is used to define an enumeration type, which represents a set of named integer constants.
- The
Explain the difference between local and global static variables.
- Local static variables are declared inside a function and retain their values between function calls. Global static variables are declared outside any function and are visible only within the file they are declared in.
How do you define a macro in C using the
#definedirective?- A macro is defined using the
#definedirective, like this:#define MAX_SIZE 100.
- A macro is defined using the
What is the purpose of the
sizeofoperator when used with a data type?- The
sizeofoperator returns the size, in bytes, of a data type. For example,sizeof(int)returns the size of an integer.
- The
How can you check if a number is odd or even in C without using the modulo operator?
- You can use the bitwise AND operator:
if (num & 1) { /* odd */ } else { /* even */ }.
- You can use the bitwise AND operator:
What is a function pointer, and how is it used in C?
- A function pointer is a variable that stores the address of a function. It can be used to call functions dynamically at runtime.
Explain the purpose of the
restrictkeyword in C.- The
restrictkeyword is a hint to the compiler that a pointer is the only reference to the data it points to, which can enable optimizations.
- The
How do you dynamically allocate a 2D array in C using pointers?
- You can use a pointer to a pointer (
int**) and dynamic memory allocation functions (malloc,calloc) to create a dynamic 2D array.
- You can use a pointer to a pointer (
Discuss the role of the
offsetofmacro in C.- The
offsetofmacro is used to find the offset of a member within a structure.
- The
What is a union, and how is it different from a structure?
- A union is a data structure that allows different data types to be stored in the same memory location. Unlike structures, where each member has its own memory location, union members share the same memory.
Explain the purpose of the
volatilekeyword in C.- The
volatilekeyword is used to indicate that a variable's value may change at any time outside the program's control, preventing certain compiler optimizations.
- The
What is the purpose of the
inlinekeyword in C?- The
inlinekeyword suggests to the compiler that it should attempt to integrate the function's code directly into the calling code rather than performing a traditional function call.
- The
Discuss the use of the
__FILE__and__LINE__macros in C.__FILE__is a predefined macro that expands to the current source file name, and__LINE__expands to the current line number.
Explain the purpose of the
EXIT_SUCCESSandEXIT_FAILUREmacros.- These macros are used as exit codes in C programs.
EXIT_SUCCESStypically represents a successful program execution, andEXIT_FAILURErepresents a failure.
- These macros are used as exit codes in C programs.
What is the purpose of the
assertmacro in C?- The
assertmacro is used for debugging purposes. It tests an expression and, if false, prints a diagnostic message and terminates the program.
- The
Discuss the concept of a pointer to a function in C.
- A pointer to a function stores the memory address of a function. It allows for dynamic function calls and is commonly used in scenarios like callbacks and function arrays.

No comments:
Post a Comment