Home Subjects C Programming Basics & Syntax

C Programming
Basics & Syntax

C language from basics to advanced placement prep

40 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 40
Topics in C Programming
Q.31 Medium Basics & Syntax
What will be the output of the following code?
#include
int main() {
int x = 10, y = 20;
int *p = &x, *q = &y;
*p = *q;
printf("%d %d", x, y);
return 0;
}
A 10 20
B 20 20
C 10 10
D 20 10
Correct Answer:  B. 20 20
EXPLANATION

*p = *q assigns the value of y (20) to x through the pointer p. So x becomes 20, y remains 20.

Test
Q.32 Medium Basics & Syntax
What will be printed by the following code?
#include
int main() {
float f = 0.1 + 0.2;
if(f == 0.3)
printf("Equal");
else
printf("Not Equal");
return 0;
}
A Equal
B Not Equal
C Compiler Error
D Runtime Error
Correct Answer:  B. Not Equal
EXPLANATION

Due to floating-point precision limitations, 0.1 + 0.2 does not exactly equal 0.3 in binary representation.

Test
Q.33 Medium Basics & Syntax
What is the size of the following structure in bytes (assuming 32-bit system)?
struct Point {
char c;
int x;
double d;
}
A 13
B 16
C 17
D 20
Correct Answer:  B. 16
EXPLANATION

Due to structure padding and alignment: char (1 byte) + padding (3 bytes) + int (4 bytes) + double (8 bytes) = 16 bytes.

Test
Q.34 Medium Basics & Syntax
What is the output of: printf("%f", 7/2);
A 3.5
B 3.0
C 3
D undefined
Correct Answer:  B. 3.0
EXPLANATION

7/2 performs integer division resulting in 3. Using %f format specifier prints it as 3.0 (or similar float representation).

Test
Q.35 Medium Basics & Syntax
Which of the following correctly represents a character constant in C?
A "A"
B 'A'
C A
D 'AB'
Correct Answer:  B. 'A'
EXPLANATION

Character constants in C use single quotes ('A'). Double quotes ("") are for string literals. A single character in double quotes is a string, not a character constant.

Test
Q.36 Medium Basics & Syntax
What will happen if we try to modify a const variable in C?
A Runtime error
B Compilation error
C It will modify successfully
D No error, but warning
Correct Answer:  B. Compilation error
EXPLANATION

Attempting to modify a const variable results in a compilation error as const variables are read-only.

Test
Q.37 Medium Basics & Syntax
Consider: void func(int *p); Which statement is correct about this function declaration?
A func takes an integer as parameter
B func takes a pointer to integer as parameter
C func returns a pointer
D func cannot be called
Correct Answer:  B. func takes a pointer to integer as parameter
EXPLANATION

The * in the parameter declaration indicates that func takes a pointer to an integer, not an integer value.

Test
Q.38 Medium Basics & Syntax
What is the return type of strlen() function?
A int
B char
C size_t
D float
Correct Answer:  C. size_t
EXPLANATION

strlen() returns size_t, which is an unsigned integer type used for sizes and counts.

Test
Q.39 Medium Basics & Syntax
Which of the following is the correct way to define a constant in C?
A #define PI 3.14
B const float PI = 3.14;
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 #define and const can be used to define constants in C. #define is a preprocessor directive, while const is a type qualifier.

Test
Q.40 Medium Basics & Syntax
Which of the following is NOT a valid C keyword?
A extern
B volatile
C mutable
D register
Correct Answer:  C. mutable
EXPLANATION

mutable is a C++ keyword, not a C keyword. extern, volatile, and register are valid C keywords.

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