Home Subjects Computer Knowledge C Programming

Computer Knowledge
C Programming

Programming, networking, database and OS questions

60 Q 2 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 21–30 of 60
Topics in Computer Knowledge
All C Programming 200 Database/SQL 100
Q.21 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.

Test
Q.22 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.

Test
Q.23 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.

Test
Q.24 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.

Test
Q.25 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.

Test
Q.26 Easy C Programming
What will be the output of: printf("%d", 5/2);
A 2.5
B 2
C 3
D 2.0
Correct Answer:  B. 2
EXPLANATION

Integer division truncates the decimal part. 5/2 = 2 (not 2.5) because both operands are integers.

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

Both syntaxes are correct. C allows initializing 2D arrays with or without explicit braces for each row.

Test
Q.28 Easy C Programming
What will be the output of: #define MAX 10; int x = MAX; printf("%d", x);
A 10
B Error
C MAX
D Undefined
Correct Answer:  A. 10
EXPLANATION

The #define directive replaces MAX with 10 during preprocessing. So x = 10 and output is 10. (Note: semicolon after MAX is not needed but doesn't affect the output)

Test
Q.29 Easy C Programming
What will be the output of: char *s = "Hello"; printf("%d", strlen(s));
A 5
B 6
C 4
D Error
Correct Answer:  A. 5
EXPLANATION

strlen() counts characters excluding the null terminator. "Hello" has 5 characters, so strlen(s) returns 5.

Test
Q.30 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.

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