Search Header Logo

Sessional 2 A3

Authored by Gunjan Verma

Computers

University

Used 3+ times

Sessional 2 A3
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

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

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?