What is the purpose of the break statement in a loop?
Answer: B
The break statement exits or terminates the current loop immediately. Option D describes continue (which skips to next iteration), while break actually exits the loop.
Q.22Easy
In C programming, which of the following is NOT a valid data type?
Answer: C
In C, 'string' is not a primitive data type. C uses 'char' arrays to represent strings. The valid primitive data types are int, float, double, char, void, and their variants.
Q.23Easy
What will be the output of: int a = 10; int b = 20; int c = a + b; printf("%d", c);?
Answer: B
Variable 'a' is initialized to 10, 'b' is initialized to 20. When c = a + b, c becomes 10 + 20 = 30. Therefore, printf outputs 30.
Q.24Easy
Which of the following is used to declare a constant in C?
Answer: B
In C, the 'const' keyword is used to declare constants. Once a const variable is initialized, its value cannot be changed. Options A, C, and D are not valid C syntax.
Q.25Easy
What is the purpose of the return statement in a C function?
Answer: B
The return statement is used to exit a function and return a value (if any) to the calling function. If the function has return type void, no value is returned.
Advertisement
Q.26Easy
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.
Q.27Easy
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.28Easy
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.29Easy
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.30Easy
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.31Easy
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.
Q.32Easy
What will be the output of: char *s = "Hello"; printf("%d", strlen(s));
Answer: A
strlen() counts characters excluding the null terminator. "Hello" has 5 characters, so strlen(s) returns 5.
Q.33Easy
What will be the output of: #define MAX 10; int x = MAX; printf("%d", x);
Answer: A
The #define directive replaces MAX with 10 during preprocessing. So x = 10 and output is 10. (Note: semicolon after MAX is not needed but doesn't affect the output)
Q.34Easy
Which of the following correctly initializes a 2D array?
Answer: C
Both syntaxes are correct. C allows initializing 2D arrays with or without explicit braces for each row.
Q.35Easy
What will be the output of: printf("%d", 25);
Answer: B
Integer division truncates the decimal part. 25 = 2 (not 2.5) because both operands are integers.
Q.36Easy
What does the getchar() function do?
Answer: A
getchar() reads a single character from standard input (stdin) and returns its ASCII value.
Q.37Easy
What will be the output of: int a = 5, b = 5; if(a == b) printf("Equal"); else printf("Not Equal");
Answer: A
The == operator compares values. Since a and b both have value 5, the condition is true and "Equal" is printed.
Q.38Easy
Which header file is essential for using the printf() function in C?
Answer: B
The stdio.h header file contains declarations for standard input/output functions like printf(). Option A is C++, Option C is C++, and Option D is for memory allocation functions.
Q.39Easy
Which of the following is a correct way to declare a pointer to an integer in C?
Answer: B
The correct syntax for declaring a pointer to an integer is 'int *ptr;' where the asterisk (*) indicates it is a pointer variable.
Q.40Easy
What is the output of the following code: printf("%d", sizeof(int));
Answer: C
sizeof(int) returns the size of integer in bytes as an integer value. On most modern systems, this is 4 bytes, and printf with %d will print this numeric value.