Sessional 2 A3

Sessional 2 A3

University

20 Qs

quiz-placeholder

Similar activities

Array Addresses 2024

Array Addresses 2024

University

20 Qs

Pointers in C

Pointers in C

University

24 Qs

C Programming Quiz

C Programming Quiz

12th Grade - University

20 Qs

C - Structures

C - Structures

University

20 Qs

Structures and union

Structures and union

University

15 Qs

C++ Quiz-1

C++ Quiz-1

University

15 Qs

Bridge course with C

Bridge course with C

University

20 Qs

Programming Round 1

Programming Round 1

12th Grade - University

21 Qs

Sessional 2 A3

Sessional 2 A3

Assessment

Quiz

Computers

University

Hard

Created by

Gunjan Verma

Used 3+ times

FREE Resource

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What will be the output of this code?

int x = 5;

printf("%d %d %d", x++, ++x, x);

5 6 6
6 6 7
5 5 5
5 7 7

2.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

What will happen if you write the following declaration in C?

const int x = 10;

int *ptr = &x;

*ptr = 20;

printf("%d", x);

The program will likely print 10, but modifying a const variable through a pointer leads to undefined behavior.
The program will print 20, as the value of x is changed.
The program will print an error message at runtime.
The program will cause a compilation error due to the pointer assignment.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is true about variable scope in C?

C does not support any form of variable scope.
All variables in C are automatically local to functions.
Variables in C can have block scope or file scope.
Variables in C can only have global scope.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How does C interpret the expression int x = (int *) malloc(sizeof(int));?

The expression is incorrect; it should declare x as a pointer.
The expression will compile without any errors.
malloc is not needed for allocating memory in C.
The expression correctly declares x as an integer.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following switch cases is invalid?

switch (x) {

case 1.5: printf("Float\n"); break;

case 'a': printf("Char\n"); break;

case 3: printf("Int\n"); break;

}

case 1.5
case 4: printf("Float\n"); break;
case 'b': printf("Char\n"); break;
case 2.5: printf("Double\n"); break;

6.

MULTIPLE CHOICE QUESTION

20 sec • 1 pt

Consider this code:

for (int i = 0; i < 5; i++)

{

if (i == 3) break;

}

printf("%d", i);

4
3
2
5

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will the output of the following recursive function be?

int func(int n)

{

if (n == 0) return 0; return n + func(n - 1);

}

printf("%d", func(4));

10
6
12
8

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?