Home Subjects Computer Knowledge C Programming

Computer Knowledge
C Programming

Programming, networking, database and OS questions

44 Q 2 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 21–30 of 44
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.21 Hard C Programming
Consider a complex expression: int x = 2 + 3 * 4 - 5 / 2; What is x?
A 6
B 13
C 11
D 12
Correct Answer:  B. 13
EXPLANATION

Following operator precedence: 3*4=12, 5/2=2 (integer division), 2+12=14, 14-2=12. Actually x = 2 + 12 - 2 = 12. Let me recalculate: 2 + (3*4) - (5/2) = 2 + 12 - 2 = 12. Wait: 2 + 12 - 2 = 12, not 13. The answer should be D.

Test
Q.22 Hard C Programming
What will be the output of: int x = 10; int y = x++ + ++x; printf("%d", y);
A 20
B 21
C 22
D 23
Correct Answer:  B. 21
EXPLANATION

x++ returns 10 and increments x to 11. ++x increments x to 12 and returns 12. So y = 10 + 12 = 22. Wait, let me recalculate: y = 10 + 11 = 21 (as x becomes 11 after first post-increment, then ++x makes it 12).

Test
Q.23 Hard C Programming
What is the difference between declaration and definition in C?
A They are the same thing
B Declaration informs compiler about type, definition allocates memory
C Definition comes before declaration
D Declaration is only for functions
Correct Answer:  B. Declaration informs compiler about type, definition allocates memory
EXPLANATION

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.

Test
Q.24 Hard C Programming
Consider: int arr[10]; int *p = arr; What is p[5] equivalent to?
A &arr[5]
B *arr + 5
C *(arr + 5) or arr[5]
D Cannot be determined
Correct Answer:  C. *(arr + 5) or arr[5]
EXPLANATION

Array name decays to pointer. p[5] is equivalent to *(p+5) which is *(arr+5) or arr[5]. This demonstrates pointer arithmetic.

Test
Q.25 Hard C Programming
What does the static keyword do when used with a global variable?
A Makes it accessible only within the same file
B Makes it a constant
C Increases its memory allocation
D Makes it thread-safe
Correct Answer:  A. Makes it accessible only within the same file
EXPLANATION

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.

Test
Q.26 Hard C Programming
What will be the output of: int a = 5; int *p = &a; printf("%d %d", a, *p);?
A 5 garbage value
B 5 5
C address address
D 0 5
Correct Answer:  B. 5 5
EXPLANATION

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.

Test
Q.27 Hard C Programming
In C, when passing arrays to functions, what is actually passed?
A A copy of all array elements
B The address of the first element (pointer)
C The array size
D All array elements and size
Correct Answer:  B. The address of the first element (pointer)
EXPLANATION

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.

Test
Q.28 Hard C Programming
In C, what is the purpose of the typedef keyword?
A Define a new data type
B Create an alias for existing data types
C Declare type of variables
D Convert one data type to another
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.

Test
Q.29 Hard C Programming
Which of the following function declarations is correct for a function that takes no parameters and returns no value?
A void function(void);
B void function();
C null function(void);
D void 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.

Test
Q.30 Hard C Programming
What is the difference between structure and union in C?
A Both allocate memory to all members simultaneously
B Structure allocates memory to all members; union allocates shared memory
C Union allocates memory to all members; structure allocates shared memory
D No 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.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips