C Programming
C language from basics to advanced placement prep
198 Questions 10 Topics Take Test
Advertisement
Showing 181–190 of 198 questions
Q.181 Hard Basics & Syntax
Which of the following correctly uses memcpy()?
A memcpy(dest, src, strlen(src));
B memcpy(dest, src, sizeof(src));
C memcpy(&dest, &src, count);
D memcpy(dest, src, count);
Correct Answer:  D. memcpy(dest, src, count);
EXPLANATION

memcpy(dest, src, count) copies 'count' bytes from src to dest. strlen() and sizeof() may not give correct results for all data types.

Take Test
Q.182 Hard Basics & Syntax
What is the output of: float x = 5/2; printf("%f", x);
A 2.5
B 2.0
C 2.500000
D Error
Correct Answer:  B. 2.0
EXPLANATION

5/2 is integer division (not float division), so result is 2 (integer), then converted to 2.0 (float).

Take Test
Q.183 Hard Basics & Syntax
Which of the following about function pointers in C is correct?
A int *func();
B int (*func)();
C int func*();
D int *func*();
Correct Answer:  B. int (*func)();
EXPLANATION

int (*func)(); declares a pointer to a function that returns int. Option A declares a function returning pointer to int.

Take Test
Q.184 Hard Basics & Syntax
What will be the output of: int a = 1; int b = 2; a = a + b; b = a - b; a = a - b; printf("%d %d", a, b);
A 1 2
B 2 1
C 3 1
D 1 3
Correct Answer:  B. 2 1
EXPLANATION

Initial: a=1, b=2. After step 1: a=3, b=2. After step 2: a=3, b=1. After step 3: a=2, b=1. Output is '2 1'.

Take Test
Q.185 Hard Basics & Syntax
What is the scope of a variable declared inside a block with 'static'?
A Global scope
B Function scope
C Block scope with static storage duration
D File scope
Correct Answer:  C. Block scope with static storage duration
EXPLANATION

A static variable declared in a block has block scope but static storage duration, persisting between function calls.

Take Test
Advertisement
Q.186 Hard Basics & Syntax
What is the output of: int x = 5; int y = ++x + x++;
A y = 12
B y = 13
C Undefined behavior
D Compilation error
Correct Answer:  C. Undefined behavior
EXPLANATION

This involves undefined behavior due to modification of x multiple times without intervening sequence points.

Take Test
Q.187 Hard Basics & Syntax
What is the result of: int x = 10; int y = x++ + x++;
A y = 20
B y = 21
C y = 22
D Undefined behavior
Correct Answer:  D. Undefined behavior
EXPLANATION

Multiple post-increments without sequence points lead to undefined behavior.

Take Test
Q.188 Hard Basics & Syntax
What will be the output of: int x = 5; printf("%d", x++ + ++x);
A 11
B 12
C 10
D Undefined behavior
Correct Answer:  D. Undefined behavior
EXPLANATION

This exhibits undefined behavior due to multiple modifications of the same variable 'x' without intervening sequence points.

Take Test
Q.189 Hard Basics & Syntax
Which of the following best describes the 'register' storage class in modern C compilers?
A Guarantees storage in CPU register
B A hint to the compiler to optimize variable storage; compiler may ignore it
C Forces the variable to be global
D Automatically allocates memory on the stack
Correct Answer:  B. A hint to the compiler to optimize variable storage; compiler may ignore it
EXPLANATION

The 'register' keyword is a hint for compiler optimization. Modern compilers often ignore it as they have sophisticated optimization strategies.

Take Test
Q.190 Hard Basics & Syntax
What is the output of: printf("%d", (int)3.7);?
A 3.7
B 3
C 4
D Error
Correct Answer:  B. 3
EXPLANATION

Type casting (int)3.7 truncates the decimal part, converting 3.7 to 3. The fractional part is discarded.

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