Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

309 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 181–190 of 309
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.181 Medium C Programming
Which of the following is NOT a valid way to pass arguments to a function in C?
A Pass by value
B Pass by reference
C Pass by pointer
D All 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.

Take Test
Q.182 Medium C Programming
What will be the output of: int x = 5, y = 10; if (x < y) printf("yes"); else printf("no");
A yes
B no
C Compilation error
D No output
Correct Answer:  A. yes
EXPLANATION

The condition x < y evaluates to true (5 < 10), so the if block executes, printing 'yes'. The else block is skipped.

Take Test
Q.183 Medium C Programming
What is the purpose of the break statement in a switch case?
A To exit the program
B To exit the current loop or switch
C To skip the next statement
D To pause execution
Correct Answer:  B. To exit the current loop or switch
EXPLANATION

The break statement terminates the current loop or switch block and transfers control to the statement following the loop or switch. Without it, execution continues to the next case (fall-through).

Take Test
Q.184 Medium C Programming
Which function is used to allocate memory dynamically at runtime?
A alloc()
B malloc()
C memalloc()
D allocate()
Correct Answer:  B. malloc()
EXPLANATION

malloc() is the standard C library function for dynamic memory allocation. It returns a void pointer to the allocated memory block, which can be cast to the required data type.

Take Test
Q.185 Medium C Programming
What is the output of: int arr[5]; printf("%d", sizeof(arr));
A 5
B 10
C 20
D 1
Correct Answer:  C. 20
EXPLANATION

sizeof(arr) returns the total size of the array in bytes. An array of 5 integers, where each int is 4 bytes, equals 5 × 4 = 20 bytes.

Take Test
Q.186 Easy C Programming
Which header file is essential for using the printf() function in C?
A #include
B #include
C #include
D #include
Correct Answer:  B. #include
EXPLANATION

The stdio.h header file contains declarations for standard input/output functions like printf(). Option A is C++, Option C is C++, and Option D is for memory allocation functions.

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

Take Test
Q.188 Medium C Programming
What will be the output of: char c = 'A'; printf("%d", c);
A 65
B A
C Error
D 1
Correct Answer:  A. 65
EXPLANATION

The %d format specifier prints the ASCII value of the character. 'A' has ASCII value 65.

Take Test
Q.189 Easy C Programming
What will be the output of: int a = 5, b = 5; if(a == b) printf("Equal"); else printf("Not Equal");
A Equal
B Not Equal
C Syntax Error
D No output
Correct Answer:  A. Equal
EXPLANATION

The == operator compares values. Since a and b both have value 5, the condition is true and "Equal" is printed.

Take Test
Q.190 Easy C Programming
What does the getchar() function do?
A Reads a single character from input
B Reads a string from input
C Displays a character
D Returns ASCII value of a character
Correct Answer:  A. Reads a single character from input
EXPLANATION

getchar() reads a single character from standard input (stdin) and returns its ASCII value.

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