0% found this document useful (0 votes)
1 views3 pages

C Programming Viva Questions With Answers

This document contains a collection of C programming viva questions and answers covering key topics such as functions, arrays, structures, unions, pointers, operators, and file handling. Each section provides fundamental concepts, definitions, and examples relevant to first-year C programming students. The content is structured in a question-and-answer format for easy reference and study.

Uploaded by

g12002656
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views3 pages

C Programming Viva Questions With Answers

This document contains a collection of C programming viva questions and answers covering key topics such as functions, arrays, structures, unions, pointers, operators, and file handling. Each section provides fundamental concepts, definitions, and examples relevant to first-year C programming students. The content is structured in a question-and-answer format for easy reference and study.

Uploaded by

g12002656
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C Programming Viva Questions with Answers (First Year)

Functions

Q1. What is a function in C?


Ans: A function is a block of code that performs a specific task. It is used to modularize a program.

Q2. What is the difference between call by value and call by reference?
Ans: Call by value passes a copy of the variable, while call by reference passes the address.

Q3. What are function prototypes?


Ans: They declare the function signature before its actual definition to help the compiler understand its usage.

Q4. Can we return more than one value from a function?


Ans: No, but we can use pointers or structures to simulate multiple return values.

Q5. What is recursion? Give an example.


Ans: Recursion is a function calling itself. Example: calculating factorial using recursion.

Arrays

Q1. What is an array in C?


Ans: An array is a collection of elements of the same type stored in contiguous memory locations.

Q2. How do you declare and initialize a 1D array and 2D array?


Ans: 1D: int arr[5] = {1,2,3,4,5}; 2D: int mat[2][2] = {{1,2},{3,4}};

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


Ans: Array is a collection of elements, pointer stores the address of a variable. Arrays are static, pointers are dynamic.

Q4. What happens if you access an array index out of bounds?


Ans: It leads to undefined behavior.

Q5. How do you pass an array to a function?


Ans: By passing the base address of the array (e.g., int func(int arr[])).

Structures

Q1. What is a structure in C?


Ans: A structure is a user-defined data type that groups related variables of different data types.

Q2. How is a structure different from an array?


Ans: Arrays hold similar data types, structures can hold different data types.

Q3. How do you access structure members?


Ans: Using the dot operator (.) or arrow operator (->) if using a pointer.

Q4. Can structures be nested?


C Programming Viva Questions with Answers (First Year)

Ans: Yes, one structure can contain another structure.

Q5. How are structures passed to functions?


Ans: They can be passed by value or by reference (using pointers).

Unions

Q1. What is a union?


Ans: A union is a user-defined data type where all members share the same memory location.

Q2. Difference between structure and union?


Ans: Structures allocate separate memory for each member; unions share the same memory.

Q3. When would you use a union?


Ans: When memory conservation is needed and only one member is used at a time.

Q4. Can a union have a structure member?


Ans: Yes, unions can have structures and vice versa.

Q5. What is the size of a union?


Ans: Size is equal to the size of its largest member.

Pointers

Q1. What is a pointer?


Ans: A pointer is a variable that stores the address of another variable.

Q2. What is the syntax for declaring a pointer?


Ans: datatype *pointer_name; e.g., int *ptr;

Q3. What is a NULL pointer?


Ans: A pointer that does not point to any memory location.

Q4. What is pointer arithmetic?


Ans: Operations like increment/decrement on pointers to traverse through memory addresses.

Q5. Can we have a pointer to a pointer?


Ans: Yes, it is called a double pointer (e.g., int **pptr).

Q6. How are pointers used in function arguments?


Ans: To pass by reference and modify values of actual parameters.

Operators

Q1. What are the types of operators in C?


C Programming Viva Questions with Answers (First Year)

Ans: Arithmetic, Relational, Logical, Assignment, Bitwise, Unary, etc.

Q2. What is the difference between == and =?


Ans: == is a comparison operator, = is an assignment operator.

Q3. What is the use of sizeof operator?


Ans: To get the memory size (in bytes) of a data type or variable.

Q4. What is operator precedence?


Ans: The order in which operators are evaluated in an expression.

Q5. What does the & and * operators mean in pointers?


Ans: & gives the address, * dereferences the pointer to get the value.

File Handling

Q1. What is file handling in C?


Ans: Reading and writing data to/from a file stored on disk.

Q2. What are the file modes in fopen()?


Ans: 'r', 'w', 'a', 'r+', 'w+', 'a+' for reading, writing, and appending.

Q3. What is the difference between fscanf and fgets?


Ans: fscanf reads formatted input; fgets reads an entire line including spaces.

Q4. What does fclose() do?


Ans: It closes the file that was opened.

Q5. What is the difference between text and binary files?


Ans: Text files store characters; binary files store data in binary form.

Q6. How do you write to a file using C?


Ans: Use functions like fprintf, fputs, or fwrite.

Q7. What is EOF?


Ans: End of File indicator, usually returned by functions like getc when file ends.

You might also like