C Programming viva
C Programming viva
MODULE 1
### 1. Introduction to C
A: Simplicity, portability, rich library, low-level memory access, modularity, and efficiency.
---
A: Must start with a letter or underscore, followed by letters or digits. No spaces or special
characters.
---
A: Typically, int = 4 bytes, float = 4 bytes, char = 1 byte, double = 8 bytes (platform
dependent).
A: double has more precision and occupies more memory than float.
A: Scope defines where the variable can be accessed. Lifetime is how long the variable exists
in memory.
---
A: Yes.
---
**Q29. What functions are used for single character input and output?**
---
A: +, -, \*, /, %
A: &&, ||, !
**Q47. What is the difference between implicit and explicit type conversion?**
---
A: Header files are included, macros are expanded, conditional compilations are handled.
8. Control Statements
Q59. What is the syntax of an if-else statement? A: if(condition) { // code } else { // code }
Q60. What is a switch statement? A: A multi-way branch statement based on the value of
an expression.
Q61. When do we use switch instead of if? A: When we have multiple values to compare
with a single variable.
Q62. What is the purpose of break statement? A: To exit a loop or switch block
prematurely.
Q63. What is the purpose of continue statement? A: To skip the current iteration and move
to the next loop cycle.
Q64. What are the different looping structures in C? A: while, do-while, for.
Q65. What is the difference between while and do-while loop? A: while checks the
condition first; do-while executes the body first.
Q66. What is the syntax of a for loop? A: for(initialization; condition; increment) { // code
}
Q67. How do you define a function in C? A: With a return type, name, parameters, and
body: int add(int a, int b) { return a + b; }
Q68. How do you access a function? A: By calling it using its name and passing required
arguments.
Q69. What is a function prototype? A: A declaration of a function before its definition: int
add(int, int);
Q71. What are return values and their types? A: The value returned by a function can be
int, float, char, etc.
Q73. What is recursion? A: A function calling itself to solve smaller instances of the
problem.
Q74. What are storage classes in C? A: Keywords that define scope, visibility, and lifetime
of variables.
Q75. What is an automatic variable? A: Declared inside a function, has local scope, and is
created/destroyed on function call.
Q76. What is an external variable? A: Declared outside all functions, accessible globally.
Q78. What is a register variable? A: Suggested to be stored in a CPU register for faster
access.
Q79. What is an array in C? A: An array is a collection of elements of the same type stored
in contiguous memory locations.
Q81. How are arrays processed in C? A: Through loops using indexing to access each
element.
Q82. What is a multidimensional array? A: An array with more than one index, like int
matrix[3][3];
Q83. How do you pass a 1-D array to a function? A: By passing the array name: void
display(int arr[])
Q84. How do you pass a 2-D array to a function? A: By specifying column size: void
display(int arr[][3])
Q85. What is a string in C? A: A sequence of characters terminated by a null character \0.
Q86. How is a string stored in C? A: As a 1-D array of characters ending with \0.
Q87. What is the use of puts() and gets()? A: gets() reads a string including spaces; puts()
prints a string.
Q88. What is an array of strings? A: A 2-D array where each row is a string: char
names[3][10];
Q89. How do you handle strings without using string functions? A: By using loops and
character arrays to process each character manually.
11. Pointers
int a = 10;
int *p = &a;
data_type member1;
data_type member2;
};
struct node {
int data;
};
union data {
int i;
float f;
char c;
};
d1.i = 10;
fopen(), fclose()
fgetc(), fputc()
fgets(), fputs()
fprintf(), fscanf()
fread(), fwrite()
char line[100];
printf("%s", line);
Enumeration
Bitwise Operators
• & (AND)
• | (OR)
• ^ (XOR)
• ~ (NOT)
#ifdef DEBUG
printf("Debugging...\n");
#endif