Variables in Depth

C Variables



Ques 1. what is the scope of var1 and var2?

int var1;
fun()
{
	int var2;
}

options:
A. The scope of var2 is accessible through out the file and var1 is accessible only inside the fun.
B. The scope of var1 is accessible through out the file and var2 is accessible only inside the fun.
C. The scope of var1 and var2 are accessible only inside the fun().
D. The scope of var1 and var2 are accessible through out the file.


Ques 2. what is the life and scope of var1 and var2?

int var1;
fun()
{
	static int var2;
}

options:
A.  The life and scope of var1 and var2 are through out the file.
B.  The life and scope of var1 and var2 are only in fun().
C.  The life and scope of var1 is through out the file. The scope of var2 is inside the fun() and life exists till the
    program running.
D.  none of these


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int v=7;
int main()
{
    int v=v;
    if(v==7)
    printf("value of v = 7\n");
    else
    printf("value of v is garbage\n");
    return 0;
}

options:
A. value of v = 7
B. value of v is garbage
C. compiler error
D. runtime error


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
extern int sum;
int main()
{
    int a,b;
    a=3, b=5;
    sum+=a+b;
    printf("%d ", sum);
    return 0;
}

options:
A. 8 
B. 20
C. 0
D. compiler error


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
extern int var = 0;
int main()
{
    if(var!=0)
        printf("\n var is not 0");
    else
        printf("\n var is 0");
    return 0;
}
options:
A. var is 0
B. var is not 0
C. compiler error
D. runtime error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    {
      int avg=0;
    }
    if(avg==0)
        printf("\n avg = %d",avg);
    return 0;
}
options:
A. avg =0
B. Compiler error
C. runtime error
D. none of these


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int a=2,b=3;
int main()
{
    float m=33.4;
    {
      int p=33;
      m=m+b;
    }
    printf("%f ", m);

    p=p+b;
    printf(" p= %d",p);
    return 0;
}

options:
A. runtime error
B. Compiler error
C. 36.4 36
D. 36.4  3



Ques 8. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int a=2,b=3;
int main()
{
    float m=33.4;
    {
      int p=33;
      m=m+b;
      b=p+b;
    }
    printf("%2.2f ", m);
    printf(" p= %d",b);
    return 0;
}

options:
A. 36.4 36
B. compiler error
C. runtime error
D. 33.4 3



Ques 9. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int x=035, y=0x15;
int main()
{
    printf("x=%d y=%d ", x,y);
    return 0;
}

options:
A. 35 21
B. 35 15
C. 29 21
D. none of these


Ques 10. which variable has highest scope?

#include <stdio.h>
#include <stdlib.h>

int x=35;

void fun()
{
   int y =33;
}
int z=33;
int main()
{
    int p=3;
    return 0;
}

options:
A. y
B. z
C. p
D. x



Ques 11. what is the valid variables in the below code?
#include <stdio.h>
#include <stdlib.h>
int 2x = 35;

int main()
{
    int mm_2 = 35;
    int _ = 6;

    return 0;
}

options:
A. 2x and mm_2
B. mm_2 _
C. 2x and _
D. mm_2 and _


Ques 12. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int *p ;

int main()
{
    int *q=NULL;
    if(p=q)
        printf(" equal\n");
    else
        printf(" not equal\n");

    return 0;
}

options:
A. equal
B. not equal
C. compiler error
D. runtime error


Ques 13. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int *p ;

int main()
{
    int *q=NULL;
    if(p==q)
        printf(" equal\n");
    else
        printf(" not equal\n");

    return 0;
}


options:
A. not equal
B. equal
C. runtime error
D. none of these


Ques 14. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int *p ;
void fun(int *m)
{
 *m=*m+5;
 printf("m = %d ",*m);
}

int main()
{
    int s=23;
    int *q=&s;
    fun(q);
    printf("q = %d", *q);
    return 0;
}

options:
A. 28 28
B. run time error
C. compiler error
D. 28 23


Ques 15. what is the output for the below code?
int p =43;
char q ='d';

int main()
{
    printf("%d", q);
    printf(" %0.2f", p);
    return 0;
}
options:
A. 100 0.00
B. d 43
C. compiler error 
D. none of these



Answers

1. B 2. C 3. B 4. D 5. A 6. B 7. B 8. A 9. C 10. D 11. D 12. C 13. B 14. A 15. A