Which of the following is NOT a valid way to pass arguments to a function in C?
APass by value
BPass by reference
CPass by pointer
DAll are valid
Correct Answer:
B. Pass by reference
Explanation:
C supports pass by value and pass by pointer/address. 'Pass by reference' as a concept exists in C++, not in C. In C, to achieve reference-like behavior, we use pointers.
In C, which function is used to read a string from input with space handling?
Ascanf("%s", str);
Bfgets(str, sizeof(str), stdin);
Cgets(str);
Dgetline(str);
Correct Answer:
B. fgets(str, sizeof(str), stdin);
Explanation:
fgets() is the safe way to read strings including spaces. scanf("%s") stops at whitespace, gets() is deprecated and unsafe due to buffer overflow risks.
What is the purpose of the 'static' keyword when used with a variable inside a function?
ATo make the variable global
BTo preserve the variable's value between function calls
CTo prevent the variable from being modified
DTo allocate memory on the stack
Correct Answer:
B. To preserve the variable's value between function calls
Explanation:
A static variable inside a function is initialized only once and retains its value between successive function calls. It has memory allocated in the data segment, not the stack.
Which of the following correctly represents a structure declaration in C?
Astruct {int a; char b;} s;
Bstruct Name {int a; char b;};
CBoth A and B are correct
DNeither A nor B is correct
Correct Answer:
C. Both A and B are correct
Explanation:
Both are valid syntax. Option A declares an anonymous structure with immediate variable instantiation. Option B declares a named structure type that can be used later to create variables.
What will be the final value of x: int x = 5; x += 3 * 2; printf("%d", x);
A16
B11
C13
D36
Correct Answer:
A. 16
Explanation:
Step 1:x = 5. Step 2: 3 * 2 = 6 (multiplication has higher precedence). Step 3: x += 6 means x = x + 6 = 5 + 6 = 11. Wait, let me recalculate: x = 5; x += 6 gives x = 11. The answer should be B (11), not A. Correction: The correct answer is B.
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