Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

150 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 101–110 of 150
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.101 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.102 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.103 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.104 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.105 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
Q.106 Medium C Programming
What is the return type of the malloc() function?
A int
B void*
C char*
D null
Correct Answer:  B. void*
EXPLANATION

malloc() returns a void pointer (void*) which can be cast to any pointer type. It returns NULL if memory allocation fails.

Take Test
Q.107 Medium C Programming
What is the output of the following program: int x = 5; if(x > 3) printf("Greater"); else printf("Smaller");?
A Smaller
B Greater
C 5
D Error
Correct Answer:  B. Greater
EXPLANATION

x=5 is greater than 3, so the condition (x > 3) evaluates to true. The if block executes, printing 'Greater'.

Take Test
Q.108 Medium C Programming
Which of the following is the correct way to define a function that takes no parameters and returns no value?
A void function() { }
B null function() { }
C empty function() { }
D void function(void) { }
Correct Answer:  A. void function() { }
EXPLANATION

In C, void function() { } is correct. In some contexts, void function(void) { } is more explicit. Options B and C use invalid keywords for this purpose.

Take Test
Q.109 Medium C Programming
What will be the output of: for(int i = 0; i < 3; i++) { printf("%d ", i); }?
A 0 1 2
B 1 2 3
C 0 1 2 3
D 3 2 1
Correct Answer:  A. 0 1 2
EXPLANATION

Loop runs with i=0,1,2. When i=3, condition i<3 becomes false and loop terminates. Output: 0 1 2 (with spaces).

Take Test
Q.110 Medium C Programming
In C, what does the scanf() function do?
A Displays output to the screen
B Reads input from standard input (keyboard)
C Creates a new variable
D Allocates memory
Correct Answer:  B. Reads input from standard input (keyboard)
EXPLANATION

scanf() reads formatted input from the standard input device (usually keyboard). printf() displays output. Both require #include <stdio.h>.

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