wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Coding club Summit Online Quiz

Total questions: 15

Worksheet time: 15mins

Name
Class
Date
1.

In C, what is the purpose of the restrict keyword

a)

Specifies that a pointer is the only pointer to the data

b)

Allocates memory dynamically

c)

Declares a variable as a constant

d)

Specifies that a variable cannot be modified

2.

What is the primary use of the setjmp and longjmp functions in C

a)

Memory allocation

b)

Exception handling

c)

Dynamic linking

d)

File I/O operations

3.

What will be the output of the following C code?

 

    #include <stdio.h>

    void main()

    {

        int a[3] = {1, 2, 3};

        int *p = a;

        printf("%p\t%p", p, a);

    }

a)

Same address is printed

b)

Different address is printed

c)

Compile time error

d)

Nothing

4.

What will be the output of the following code snippet?

#include <stdio.h>

int main() {

    int a, b = 5;

    a = b + NULL;

    printf("%d", a);

    return 0;

}

a)

Compilation Error      

b)

Runtime Error       

c)

Logical Error        

d)

None of these

5.

What is the output of the following code snippet?

#include <stdio.h>

int main() {

    int x = 10;

    int *ptr = &x;

    printf("%d", *ptr);

    return 0;

}

a)

Memory address of x

b)

10

c)

Compilation error

d)

None of these

6.

What will be the output of the following C code?

void main() {

  char *p;

  p = "Hello";

  printf("%c\n", &p);

}

a)

Hello

b)

E

c)

Some address will be printed

d)

None of these

7.

What will be the output of the following C code?

#include <stdio.h>

    int main()

    {

        int i = 97, *p = &i;

        ABC(&i);

        printf("%d ", *p);

    }

    void ABC(int *p)

    {

        int j = 2;

        p = &j;

        printf("%d ", *p);

    }

a)

2   97

b)

2   2

c)

Compile time error

d)

Segmentation fault/code crash

8.

Which of the following is FALSE about typedef

a)

typedef follow scope rules

b)

typedef defined substitutes can be redefined again. (Eg: typedef char a; typedef int a;)

c)

You cannot typedef a typedef with other term.

d)

All of the mentioned

9.

void * malloc(size_t n) returns:

a)

Pointer to n bytes of uninitialized storage

                  

b)

NULL if the request cannot be satisfied

c)

Nothing

d)

Both a & b are true   

10.

What will be the output of the following C code?

 

    #include <stdio.h>

    int main()

    {

        int i = 10;

        int *const p = &i;

        XYZ(&p);

        printf("%d\n", *p);

    }

    void XYZ(int **p)

    {

        int j = 11;

        *p = &j;

        printf("%d\n", **p);

    }

a)

10 11

b)

Compile time error

c)

Segmentation fault/code-crash

d)

None of these

11.

What will be the output of the following C code?

 

    #include <stdio.h>

    void m(int *p)

    {

        int i = 0;

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

        printf("%d\t", p[i]);

    }

    void main()

    {

        int a[5] = {6, 5, 3};

        m(&a);

    }

a)

0 0 0 0 0

b)

6 5 3 0 0

c)

Run time error

d)

6 5 3 junk junk

12.

Output of following program?

# include <stdio.h>

void fun(int *ptr)

{

    *ptr = 30;

}

 int main()

{

  int y = 20;

  fun(&y);

  printf("%d", y);

 

  return 0;

}

a)

20

b)

30

c)

Compiler Error

d)

Runtime Error

13.

Assume that float takes 4 bytes, predict the output of following program.

#include <stdio.h>

 int main()

{

    float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5};

    float *ptr1 = &arr[0];

    float *ptr2 = ptr1 + 3;

    printf("%f ", *ptr2);

    printf("%d", ptr2 - ptr1);

    return 0;

}

a)

90.500000 3

b)

90.500000 12

c)

10.000000 12

d)

0.500000 3

14.

What is the output of this C code?

 

int main()

{

char *p = NULL;

char *q = 0;

if (p)

printf(" p ");

else

printf("nullp");

if (q)

printf("q\n");

else

printf(" nullq\n");

}

a)

nullp  nullq

b)

Depends on the compiler

c)

x nullq where x can be p or nullp depending on the value of NULL

d)

p   q

15.

What is the output of this C code?

 

int *f();

int main()

{

int *p = f();

printf("%d\n", *p);

}

int *f()

{

int j = (int)malloc(sizeof(int));

*j = 10;

return j;

}

a)

Undefined behaviour

b)

Compile time error

c)

Segmentation fault/runtime crash since pointer to local variable is returned

d)

None of these