Variable Declaration And Scope

8 Questions | Attempts: 110
Share
SettingsSettings
Please wait...
  • 1/8 Questions

    #include <stdio.h> extern int var; int main() {     var = 10;     printf("%d ", var);     return 0; }

    • Compiler Error: var is not defined
    • 20
    • 0
Please wait...

Quiz Preview

  • 2. 

    Consider the following C program, which variable has the longest scope?int a; int main() {    int b;    // ..   // ..} int c; 

    • A

    • B

    • C

    • All have same scope

    Correct Answer
    A. A
  • 3. 

    Output?#include <stdio.h> int main() {   int x = 1, y = 2, z = 3;   printf(" x = %d, y = %d, z = %d \n", x, y, z);   {        int x = 10;        float y = 20;        printf(" x = %d, y = %f, z = %d \n", x, y, z);        {              int z = 100;              printf(" x = %d, y = %f, z = %d \n", x, y, z);        }   }   return 0; }

    • X = 1, y = 2, z = 3 x = 10, y = 20.000000, z = 3 x = 1, y = 2, z = 100

    • Compiler Error

    • X = 1, y = 2, z = 3 x = 10, y = 20.000000, z = 3 x = 10, y = 20.000000, z = 100

    • X = 1, y = 2, z = 3 x = 1, y = 2, z = 3 x = 1, y = 2, z = 3

    Correct Answer
    A. X = 1, y = 2, z = 3 x = 10, y = 20.000000, z = 3 x = 10, y = 20.000000, z = 100
  • 4. 

    #include <stdio.h> extern int var = 0; int main() {     var = 10;     printf("%d ", var);     return 0; }

    • 10

    • Compiler Error: var is not defined

    • 0

    Correct Answer
    A. 10
  • 5. 

    Output?int main() {   {       int var = 10;   }   {       printf("%d", var);    }   return 0; }

    • 10

    • Compiler Error

    • Garbage value

    Correct Answer
    A. Compiler Error
  • 6. 

    Consider the following two C linesint var1; extern int var2;Which of the following statements is correct

    • Both statements only declare variables, don't define them

    • First statement declares and defines var1, but second statement only declares var2

    • Both statements declare define variables var1 and var2

    Correct Answer
    A. First statement declares and defines var1, but second statement only declares var2
  • 7. 

    Int main() {   int x = 032;   printf("%d", x);   return 0; }

    • 32

    • 0

    • 26

    • 50

    Correct Answer
    A. 26
  • 8. 

    Predict the output#include <stdio.h> int var = 20; int main() {     int var = var;     printf("%d ", var);     return 0; } 

    • Garbage Value

    • 20

    • Compiler Error

    • Option 4

    Correct Answer
    A. Garbage Value

Quiz Review Timeline (Updated): Dec 23, 2014 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Dec 23, 2014
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 23, 2014
    Quiz Created by
    Jawahar Ganesh
Back to Top Back to top
Advertisement