C Programming Viva Questions with Answers (New)

 Here are some C programming viva questions that could be asked in an interview or examination:

1. What is C programming language and its features?

2. What are the basic data types in C?

3. What is the difference between an array and a pointer?

4. What is a function in C? What is a library function?

5. What is a pointer in C? What is a null pointer? What is a void pointer?

6. What is dynamic memory allocation? How can it be done in C?

7. What is a structure in C? What is a union?

8. What is the difference between local and global variables in C?

9. What is a file in C? How can we open and close a file?

10. What is recursion? Give an example of a recursive function.

11. What is a preprocessor in C? What are the different directives of preprocessor?

12. What is the difference between a while loop and a do-while loop?

13. What is the difference between ++i and i++?

14. What is the difference between call by value and call by reference?

15. What is the significance of the main() function in C?

16. What is a pointer to a function? How is it declared and used?

17. What is a typedef in C? Give an example.

18. What is a header file in C? Give an example.

19. What is the scope and lifetime of a variable in C?

20. What is an enumeration in C?

Sure, here are sample answers to the C programming viva questions I listed earlier:


1. What is C programming language and its features?


Answer: C programming language is a high-level programming language that is used to create computer applications. Some of the features of C language include structured programming, low-level memory manipulation, portability, and a large standard library.


2. What are the basic data types in C?


Answer: The basic data types in C are integer (int), character (char), floating-point (float), double floating-point (double), and void.


3. What is the difference between an array and a pointer?


Answer: An array is a collection of elements of the same data type that are stored sequentially in memory, while a pointer is a variable that stores the memory address of another variable. In other words, an array is a group of variables of the same data type, while a pointer is a variable that points to a memory location where the data is stored.


4. What is a function in C? What is a library function?


Answer: A function in C is a group of statements that performs a specific task. It may or may not return a value. A library function is a function that is part of the C standard library and can be used in a program without having to write the function code. Examples of library functions include printf(), scanf(), and strlen().


5. What is a pointer in C? What is a null pointer? What is a void pointer?


Answer: A pointer in C is a variable that stores the memory address of another variable. A null pointer is a pointer that points to no memory location. It is represented by the value 0 or NULL. A void pointer is a pointer that can store the address of any data type.


6. What is dynamic memory allocation? How can it be done in C?


Answer: Dynamic memory allocation is the process of allocating memory during program execution. In C, it can be done using functions like malloc(), calloc(), and realloc().


7. What is a structure in C? What is a union?


Answer: A structure in C is a user-defined data type that groups together variables of different data types under a single name. A union is a user-defined data type that allows storing different data types in the same memory location.


8. What is the difference between local and global variables in C?


Answer: Local variables are declared inside a function and can only be accessed within that function. Global variables, on the other hand, are declared outside of any function and can be accessed by any function in the program.


9. What is a file in C? How can we open and close a file?


Answer: A file in C is a collection of related data that is stored on a secondary storage device like a hard disk or a flash drive. To open a file, we can use the fopen() function, and to close a file, we can use the fclose() function.

10. What is recursion? Give an example of a recursive function.

Answer: Recursion is a programming technique in which a function calls itself to solve a problem. An example of a recursive function is the factorial function:


```

int factorial(int n) {

    if (n == 0 || n == 1) {

        return 1;

    } else {

        return n * factorial(n-1);

    }

}

```

11. What is a preprocessor in C? What are the different directives of preprocessor?

Answer: The preprocessor in C is a program that processes the source code before it is compiled. It is responsible for performing tasks like macro expansion and file inclusion. Some of the directives of the preprocessor include #include, #define, and #ifdef.

12. What is the difference between

Post a Comment

Previous Post Next Post

Ads

Ad