Which of the following is the correct way to define a function that takes no parameters and returns no value?
Answer: A
In C, void function() { } is correct. In some contexts, void function(void) { } is more explicit. Options B and C use invalid keywords for this purpose.
Q.82Medium
What is the output of the following program: int x = 5; if(x > 3) printf("Greater"); else printf("Smaller");?
Answer: B
x=5 is greater than 3, so the condition (x > 3) evaluates to true. The if block executes, printing 'Greater'.
Q.83Hard
In C, when passing arrays to functions, what is actually passed?
Answer: B
When an array is passed to a function in C, it decays to a pointer pointing to the first element. This is why changes made in the function affect the original array.
Q.84Hard
What will be the output of: int a = 5; int *p = &a; printf("%d %d", a, *p);?
Answer: B
p is a pointer storing the address of a. *p (dereferencing) gives the value at that address, which is 5. So both a and *p print 5.
Q.85Easy
Which header file is required for using the printf() function?
Answer: B
stdio.h (Standard Input/Output header) contains declarations for printf(), scanf(), and other I/O functions.
Advertisement
Q.86Easy
What is the correct syntax to declare a constant in C?
Answer: D
Both 'const int x = 10;' and 'int const x = 10;' are valid ways to declare constants in C. The const keyword can appear before or after the type.
Q.87Easy
Which operator is used to access the value at an address in C?
Answer: B
The * operator is the dereference operator that accesses the value at a memory address. The & operator gets the address of a variable.
Q.88Easy
What does the sizeof() operator return?
Answer: B
sizeof() is a unary operator that returns the number of bytes occupied by a variable or data type in memory.
Q.89Easy
Which of the following is a correct way to initialize a 1D array in C?
Answer: D
All three methods are valid. Option A initializes with size 5, option B auto-determines size from initialization, and option C declares without initialization.
Q.90Medium
What is the return type of the malloc() function?
Answer: B
malloc() returns a void pointer (void*) which can be cast to any pointer type. It returns NULL if memory allocation fails.
Q.91Medium
Which function is used to release dynamically allocated memory in C?
Answer: B
The free() function deallocates memory that was previously allocated using malloc(), calloc(), or realloc(). delete() is used in C++.
Q.92Medium
What is the difference between calloc() and malloc()?
Answer: D
calloc(n, size) allocates n blocks of size bytes and initializes to 0. malloc(size) allocates size bytes without initialization. calloc() is typically slower due to initialization.
Q.93Medium
Which of the following is used to comment multiple lines in C?
Answer: B
/* */ is used for multi-line comments in C. // is used for single-line comments and was introduced in C99.
Q.94Medium
What will be the output of: float x = 25; printf("%f", x);
Answer: B
Since both 5 and 2 are integers, integer division occurs (25 = 2). The result 2 is then converted to float as 2.000000.
Q.95Medium
How are structures different from unions in C?
Answer: A
In structures, each member has its own memory location. In unions, all members share the same memory location, so only one can hold a value at a time.
Q.96Hard
What does the static keyword do when used with a global variable?
Answer: A
When static is used with a global variable, it restricts its scope to the file where it is declared. Without static, global variables are accessible across files using extern.
Q.97Hard
Consider: int arr[10]; int *p = arr; What is p[5] equivalent to?
Answer: C
Array name decays to pointer. p[5] is equivalent to *(p+5) which is *(arr+5) or arr[5]. This demonstrates pointer arithmetic.
Q.98Hard
What is the difference between declaration and definition in C?
Answer: B
Declaration tells the compiler about a variable's name and type (e.g., 'extern int x;'). Definition actually allocates memory (e.g., 'int x = 5;'). A variable can be declared multiple times but defined only once.
Q.99Medium
What will be the output of the following code?
int a = 5;
int b = ++a + a++;
printf("%d", b);
Answer: B
++a increments a to 6 and returns 6. Then a++ returns 6 and increments a to 7. So b = 6 + 6 = 12.
Q.100Easy
What is the size of an empty structure in C?
Answer: B
An empty structure in C has a size of 1 byte. This is to ensure each structure instance has a unique address in memory.