Exercise

1. Which of the following statements are correct about the given program?

#include<stdio.h>
int main()
{
printf("%p", main());
return 0;
}

A. Prints garbage value infinite times
B. Error
C. Runs infinite times without printing anything
D. None of the above

View Answer


2. What is the output of this program?

#include<stdio.h>
void fun(int a, ...)
{
printf("%d ", a);
}
int main()
{
fun(1,2,3,4);
fun(5,6,7,8,9);
return 0;
}

A. 1 5
B. 2 5
C. 5 1
D. Compilation Error

View Answer


3. What is the meaning of using static before function declaration?

static int demo(int a, int b)
{
return (a + b);
}

A. Access to static functions is restricted to the file where they are declared
B. Static means nothing, sum() is same without static keyword.
C. Function need not to be declared before its use
D. None of the above

View Answer


4. What is the output of this program?

#include<stdio.h>
int demo()
{
static int i = 0;
printf("%d ",i++);
}
int main()
{
for(int j = 0 ; j < 5 ; j++ )
{
demo();
}
}

A. 0 0 0 0 0
B. 1 1 1 1 1
C. 1 2 3 4 5
D. 0 1 2 3 4

View Answer


5. What is the output of this program?

#include<stdio.h>
int test()
{
static int n = 10;
return n--;
}
int main()
{
for(test(); test(); test())
printf("%d ", test());
return 0;
}

A. 7 4 1
B. 8 5 2
C. Infinite loop
D. Compilation Error

View Answer


6. What is the output of this program?
#include>stdio.h<
int main()
{
void test(), temp();
temp();
}
void test()
{
printf("2 ");
}
void temp()
{
printf("1 ");
test();
}

A. 1 0
B. 0 1
C. Compile time error as foo is local to main
D. Compile time error due to declaration of functions inside main

View Answer


7. What is the output of this program?

#include<stdio.h>
void main()
{
test();
void test()
{
printf("1");
}
}

A. 1
B. Compilation Error
C. Run Time Error
D. None of the above

View Answer


8. What is the output of this program?

#include<stdio.h>
void test(int * , int *);
void main()
{
int a = 5 , b = 6;
test(&a,&b);
printf("%d %d",a,b);
}
void test(int *p, int *q)
{
*p = *p * *q;
*q = *p / *q;
*p = *p / *q;
}

A. 30 5
B. 6 5
C. 5 6
D. None of the above

View Answer


9. What is the output of this program?

#include<stdio.h>
void test(char**);
int main()
{
char *argv[] = {"a", "b", "c", "d"};
test(argv);
return 0;
}
void test(char **p)
{
char *m;
m = (p+= sizeof(int))[-2];
printf("%s", m);
}

A. a
B. b
C. c
D. d

View Answer


10. What is the output of this program?

#include<stdio.h>
int main()
{
char *ptr = "Hello";
printf("%c", *&*&*ptr);
return 0;
}

A. H
B. Compilation Error
C. Run Time Error
D. Garbage Value

View Answer


11. What is the output of this program?

#include<stdio.h>
void test(int *a, int *b)
{
a = b;
*a = 15;
}
int x = 10, y = 20;
int main()
{
test(&x, &y);
printf("%d %d", x, y);
return 0;
}

A. 15 15
B. 10 15
C. 10 20
D. 15 20

View Answer


12. What does the following statment mean?

int (*ptr)[5];

A. ptr is an array of 5 integers
B. ptr is a pointer to an array of 5 integers
C. ptr is array of pointers to 5 integers
D. ptr is an pointer to array

View Answer


13. What is the output of this program?

#include<stdio.h>
int main()
{
int a = 5;
void *ptr = &a ;
printf("%f", *(float*)ptr);
return 0;
}

A. 5
B. 5.000000
C. 0.000000
D. 0

View Answer


14. What is the output of the given code ?

#include<stdio.h>
void main()
{
int a = 0 ;
int *const ptr = &a ;
printf("%p ", ptr);
ptr++;
printf("%p ", ptr);
}

A. 0 1
B. compilation Error
C. Run Time Error
D. None of the above

View Answer


15. What is the output of this program?

#include<stdio.h>
void main()
{
int a = 5 ;
int *b = &a ;
int **c = &b ;
printf("%d%d%d\n", a, *b, **c);
}

A. 5 garbage value garbage value
B. 5 5 garbage value
C. 5 5 5
D. Error

View Answer


16. What is the output of this program?

#include<stdio.h>
void main()
{
int arr[3] = {1, 2, 3};
int *ptr = arr;
int **temp = &ptr ;
printf("%p %p", *temp, arr);
}

A. Same Address
B. Different Address
C. 1 2
D. 2 3

View Answer



Discussion

* You must be logged in to add comment.