What happens when you try to access an array element beyond its size in C?
Answer: C
C does not perform bounds checking on arrays. Accessing beyond array bounds results in undefined behavior - it may access garbage values, crash, or seem to work without error. This is a common source of bugs.
Q.62Medium
What is the output of: int x = 10; printf("%d", x++); printf("%d", x);
Answer: B
x++ is post-increment. First printf uses current value (10), then x is incremented. Second printf uses new value (11). Output: 1011
Q.63Hard
Which of the following is the correct way to pass a string to a function in C?
Answer: D
Both char s[] (array notation) and char *s (pointer notation) are valid ways to pass strings to functions in C. C does not have a built-in string type; strings are represented as character arrays or pointers to char.
Q.64Easy
What is the size of int data type in a 32-bit system?
Answer: B
In a 32-bit system, the int data type typically occupies 4 bytes (32 bits). This is the standard size for integer types on most 32-bit architectures.
Q.65Easy
Which header file is required to use the printf() function?
Answer: B
The stdio.h (Standard Input Output) header file contains declarations for printf(), scanf(), and other input/output functions. It is essential for console I/O operations.
Advertisement
Q.66Easy
In C, which operator has the highest precedence?
Answer: C
Parentheses have the highest precedence in C. Expressions within parentheses are evaluated first, followed by arithmetic operators, then logical operators, and finally assignment operators.
Q.67Easy
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.68Medium
Which of the following correctly declares a pointer to an integer?
Answer: A
The correct syntax for declaring a pointer to an integer is 'int *ptr;' where the asterisk (*) indicates that ptr is a pointer. The placement of * before the variable name is crucial.
Q.69Medium
What will be printed if char ch = 'A'; printf("%d", ch); is executed?
Answer: B
When %d format specifier is used with a char variable, it prints the ASCII value. The ASCII value of 'A' is 65. If it were 'a', the value would be 97.
Q.70Medium
Which of the following is used to dynamically allocate memory in C?
Answer: C
malloc() (memory allocation) is the standard function in C for dynamic memory allocation. It returns a void pointer to the allocated memory. The syntax is: ptr = (type*)malloc(size);
Q.71Medium
What will be the output of: char str[] = "Hello"; printf("%c", str[1]);?
Answer: B
Array indexing in C starts from 0. str[0]='H', str[1]='e', str[2]='l', str[3]='l', str[4]='o', str[5]='\0'. Therefore, str[1] is 'e'.
Q.72Medium
Which function is used to compare two strings in C?
Answer: A
strcmp() is the standard library function used to compare two strings. It returns 0 if strings are equal, negative if first string is less, and positive if first string is greater. It's declared in string.h.
Q.73Medium
What is the output of the following: int x = 5; int *p = &x; printf("%d", *p);?
Answer: B
p is a pointer to x, so &x gives the address of x. *p (dereferencing) gives the value stored at that address, which is 5. The output will be 5.
Q.74Hard
Which of the following is an invalid identifier in C?
Answer: C
In C, identifiers can only contain alphanumeric characters (a-z, A-Z, 0-9) and underscores (_), and must start with a letter or underscore. The dollar sign ()isnotallowed,making′myvar' invalid.
Q.75Hard
What will be the output of: int x = 5; printf("%d %d", x++, ++x);?
Answer: A
x++ is post-increment (returns 5, then x becomes 6), ++x is pre-increment (x becomes 7, then returns 7). The order of evaluation in printf is implementation-dependent, but typically right to left, giving 5 7.
Q.76Hard
What is the difference between structure and union in C?
Answer: B
Structure allocates separate memory for each member (total size = sum of all members). Union shares a single memory location among all members (total size = size of largest member). This is a fundamental difference in memory allocation.
Q.77Hard
Which of the following function declarations is correct for a function that takes no parameters and returns no value?
Answer: A
The correct syntax is 'void function(void);' where 'void' in parentheses explicitly states no parameters. Option B is also valid in C (defaults to no parameters), but option A is more explicit and portable across C standards.
Q.78Hard
In C, what is the purpose of the typedef keyword?
Answer: B
typedef creates an alias (synonym) for existing data types. For example, 'typedef int Integer;' creates 'Integer' as an alias for 'int'. This improves code readability and portability. It doesn't create entirely new types, but provides alternative names.
Q.79Easy
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.80Easy
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.