What happens when you try to access an array element beyond its size in C?
ACompilation error
BRuntime error with exception
CUndefined behavior
DReturns 0 automatically
Correct Answer:
C. Undefined behavior
Explanation:
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.
Which of the following is the correct way to pass a string to a function in C?
Avoid func(string s);
Bvoid func(char s[]);
Cvoid func(char *s);
DBoth B and C
Correct Answer:
D. Both B and C
Explanation:
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.
Which of the following is an invalid identifier in C?
AmyVar
Bmy_var
Cmy$var
D_myVar
Correct Answer:
C. my$var
Explanation:
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 (\() is not allowed, making 'my\)var' invalid.
What will be the output of: int x = 5; printf("%d %d", x++, ++x);?
A5 7
B6 7
C5 6
D6 6
Correct Answer:
A. 5 7
Explanation:
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.
What is the difference between structure and union in C?
ABoth allocate memory to all members simultaneously
BStructure allocates memory to all members; union allocates shared memory
CUnion allocates memory to all members; structure allocates shared memory
DNo difference
Correct Answer:
B. Structure allocates memory to all members; union allocates shared memory
Explanation:
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.
Which of the following function declarations is correct for a function that takes no parameters and returns no value?
Avoid function(void);
Bvoid function();
Cnull function(void);
Dvoid function(null);
Correct Answer:
A. void function(void);
Explanation:
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.
Correct Answer:
B. Create an alias for existing data types
Explanation:
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.
iGET uses cookies for essential site functionality, analytics, and ads personalization (via Google AdSense). By clicking "Accept", you consent to our use of cookies.
Privacy Policy ·
Disclaimer