Home Subjects Computer Knowledge

Computer Knowledge

Programming, networking, database and OS questions

309 Q 2 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 171–180 of 309
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.171 Easy C Programming
In C, what is the difference between single quotes and double quotes?
A No difference, they are interchangeable
B Single quotes are for characters, double quotes are for strings
C Single quotes for strings, double quotes for characters
D Single quotes cannot be used in C
Correct Answer:  B. Single quotes are for characters, double quotes are for strings
EXPLANATION

In C, single quotes (') are used for single character constants (char type), while double quotes (") are used for string literals (array of characters ending with null terminator).

Take Test
Q.172 Medium C Programming
What is the output of: int x = 5; int y = ++x + x++; printf("%d %d", x, y);
A 7 12
B 6 11
C 7 13
D 6 12
Correct Answer:  A. 7 12
EXPLANATION
Step 1: x=5. Step 2: ++x makes x=6 (pre-increment, used immediately). Step 3: y = 6 + x++ = 6 + 6 = 12. Step 4: x++ increments x to 7 after use. Final: x=7, y=12.
Take Test
Q.173 Easy C Programming
Which of the following is NOT a valid identifier in C?
A _variable123
B 123_variable
C variable_123
D Variable_123
Correct Answer:  B. 123_variable
EXPLANATION

In C, an identifier cannot start with a digit. It must start with a letter (a-z, A-Z) or underscore (_). Option B violates this rule by starting with a digit.

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

When a character is printed using %d format specifier, its ASCII value is printed. The ASCII value of 'A' is 65.

Take Test
Q.175 Easy C Programming
Which of the following correctly initializes a 2D array in C?
A int arr[3][3] = {{1,2,3}, {4,5,6}, {7,8,9}};
B int arr[][3] = {1,2,3,4,5,6,7,8,9};
C Both A and B are correct
D Neither A nor B is correct
Correct Answer:  C. Both A and B are correct
EXPLANATION

Both syntaxes are valid in C. Option A explicitly specifies both dimensions, while Option B lets the compiler calculate the first dimension based on initialization.

Take Test
Q.176 Easy C Programming
What is the output of the following code: printf("%d", sizeof(int));
A 2 bytes
B 4 bytes
C The code will print a number (typically 4 on most systems)
D Error in compilation
Correct Answer:  C. The code will print a number (typically 4 on most systems)
EXPLANATION

sizeof(int) returns the size of integer in bytes as an integer value. On most modern systems, this is 4 bytes, and printf with %d will print this numeric value.

Take Test
Q.177 Easy C Programming
Which of the following is a correct way to declare a pointer to an integer in C?
A int ptr*;
B int *ptr;
C int& ptr;
D *int ptr;
Correct Answer:  B. int *ptr;
EXPLANATION

The correct syntax for declaring a pointer to an integer is 'int *ptr;' where the asterisk (*) indicates it is a pointer variable.

Take Test
Q.178 Hard C Programming
Consider: int *ptr = NULL; *ptr = 5; What will happen?
A 5 is stored at NULL address
B Segmentation fault/Access violation
C Compilation error
D No error, value is lost
Correct Answer:  B. Segmentation fault/Access violation
EXPLANATION

Attempting to dereference a NULL pointer causes undefined behavior, typically resulting in a segmentation fault (runtime error). A NULL pointer doesn't point to valid memory.

Take Test
Q.179 Hard C Programming
What happens if you declare a variable but don't initialize it in C?
A Compilation error
B It contains garbage value
C It is automatically initialized to 0
D The program crashes
Correct Answer:  B. It contains garbage value
EXPLANATION

Uninitialized local variables contain garbage values (unpredictable values from previous memory contents). Global and static variables are automatically initialized to 0, but local variables are not.

Take Test
Q.180 Medium C Programming
What will be the result of: int a = 10, b = 3; int c = a % b; printf("%d", c);
A 3
B 1
C 13
D 30
Correct Answer:  B. 1
EXPLANATION

The modulus operator % returns the remainder of division. 10 % 3 = 1 (since 10 = 3 × 3 + 1). Therefore, c = 1 and the output is 1.

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