Home Subjects Computer Knowledge C Programming

Computer Knowledge
C Programming

Programming, networking, database and OS questions

200 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 101–110 of 200
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.101 Easy C Programming
What is the size of an empty structure in C?
A 0 bytes
B 1 byte
C 4 bytes
D 8 bytes
Correct Answer:  B. 1 byte
EXPLANATION

An empty structure in C has a size of 1 byte. This is to ensure each structure instance has a unique address in memory.

Take Test
Q.102 Medium C Programming
What will be the output of the following code?
int a = 5;
int b = ++a + a++;
printf("%d", b);
A 11
B 12
C 10
D 13
Correct Answer:  B. 12
EXPLANATION

++a increments a to 6 and returns 6. Then a++ returns 6 and increments a to 7. So b = 6 + 6 = 12.

Take Test
Q.103 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.

Take Test
Q.104 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.

Take Test
Q.105 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.

Take Test
Q.106 Medium C Programming
How are structures different from unions in C?
A Structures allocate separate memory for each member, unions share memory
B Unions allocate separate memory for each member, structures share memory
C There is no difference
D Structures are faster than unions
Correct Answer:  A. Structures allocate separate memory for each member, unions share memory
EXPLANATION

In structures, each member has its own memory location. In unions, all members share the same memory location, so only one can hold a value at a time.

Take Test
Q.107 Medium C Programming
What will be the output of: float x = 5/2; printf("%f", x);
A 2.500000
B 2.000000
C 2.5
D Compilation Error
Correct Answer:  B. 2.000000
EXPLANATION

Since both 5 and 2 are integers, integer division occurs (5/2 = 2). The result 2 is then converted to float as 2.000000.

Take Test
Q.108 Medium C Programming
Which of the following is used to comment multiple lines in C?
A // comment
B /* comment */
C # comment
D -- comment
Correct Answer:  B. /* comment */
EXPLANATION

/* */ is used for multi-line comments in C. // is used for single-line comments and was introduced in C99.

Take Test
Q.109 Medium C Programming
What is the difference between calloc() and malloc()?
A calloc() initializes memory to zero, malloc() does not
B malloc() is faster than calloc()
C calloc() takes two arguments, malloc() takes one
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

calloc(n, size) allocates n blocks of size bytes and initializes to 0. malloc(size) allocates size bytes without initialization. calloc() is typically slower due to initialization.

Take Test
Q.110 Medium C Programming
Which function is used to release dynamically allocated memory in C?
A delete()
B free()
C release()
D dealloc()
Correct Answer:  B. free()
EXPLANATION

The free() function deallocates memory that was previously allocated using malloc(), calloc(), or realloc(). delete() is used in C++.

Take Test
IGET
iget AI
Online · Ask anything about exams
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