Storage Classes and Type Qualifiers in C

This Quiz on Storage Classes and Type Qualifiers in C will help you to test and validate your knowledge about the topic. It covers a variety of questions, from basic to advanced. The quiz contains 20 questions. You just have to assess all the given options and click on the correct answer.

Last Updated :
Discuss
Comments

Question 1

Which of the following is NOT a storage class in C?

  • auto

  • static

  • register

  • volatile

Question 2

What does the extern storage class specify?

  • Internal linkage

  • Global variable with static scope

  • Declaration of a variable defined elsewhere

  • Immediate memory allocation

Question 3

What is the default storage class for local variables in C?

  • static

  • auto

  • extern

  • register

Question 4

What is the key feature of a static variable inside a function?

  • It is shared across all functions

  • It resets every time the function is called

  • It retains its value between function calls

  • It is allocated in the CPU register

Question 5

Which qualifier tells the compiler not to optimize access to a variable?

  • static

  • restrict

  • const

  • volatile

Question 6

What will be the output of the following code?

C
#include <stdio.h>

void demo() {
    static int count = 0;
    count++;
    printf("%d ", count);
}

int main() {
    demo();
    demo();
    demo();
    return 0;
}


  • 1 1 1

  • 1 2 3

  • 0 1 2

  • 2 3 4

Question 7

What will be the output of the following code?

C
#include <stdio.h>

int x = 10;

void print() {
    extern int x;
    printf("%d\n", x);
}

int main() {
    print();
    return 0;
}


  • 10

  • Garbage Value

  • Compilation Error

  • 0

Question 8

What is the output of this code?

C
#include <stdio.h>

int main() {
    register int x = 5;
    printf("%d\n", x);
    return 0;
}


  • Compilation Error

  • 5

  • 0

  • Undefined behaviour

Question 9

What will happen when this code runs?

C
#include <stdio.h>

int main() {
    const int a = 5;
    int *p = &a;
    *p = 10;
    printf("%d\n", a);
    return 0;
}


  • 5

  • 10

  • Compilation error

  • Undefined Behaviour

Question 10

Which variable will retain its value across multiple calls?

C
#include <stdio.h>

void fun() {
    auto int x = 0;
    x++;
    printf("%d ", x);
}

int main() {
    fun();
    fun();
    return 0;
}


  • 1 1

  • 1 2

  • 2 3

  • 0 1

Tags:

There are 18 questions to complete.

Take a part in the ongoing discussion