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
register
keyword in C?- The
register
keyword 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 ofregister
less impactful.
- The
Explain the concept of typecasting in C.
- Typecasting involves converting a variable from one data type to another. For example,
(float) 5
performs typecasting to a float.
- Typecasting involves converting a variable from one data type to another. For example,
What is the role of the
const
keyword in a function parameter list?- In a function parameter list, the
const
keyword 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
#ifdef
and#ifndef
directives in C.#ifdef
checks if a macro is defined, while#ifndef
checks if a macro is not defined. They are commonly used for conditional compilation.
What is the purpose of the
enum
keyword in C?- The
enum
keyword 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
#define
directive?- A macro is defined using the
#define
directive, like this:#define MAX_SIZE 100
.
- A macro is defined using the
What is the purpose of the
sizeof
operator when used with a data type?- The
sizeof
operator 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
restrict
keyword in C.- The
restrict
keyword 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
offsetof
macro in C.- The
offsetof
macro 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
volatile
keyword in C.- The
volatile
keyword 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
inline
keyword in C?- The
inline
keyword 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_SUCCESS
andEXIT_FAILURE
macros.- These macros are used as exit codes in C programs.
EXIT_SUCCESS
typically represents a successful program execution, andEXIT_FAILURE
represents a failure.
- These macros are used as exit codes in C programs.
What is the purpose of the
assert
macro in C?- The
assert
macro 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