Exercise

1. What is the output of this program?

void main()
{
int a[8] = {1,2,3,4,5};
printf("%d", a[5]);
}

A. 5
B. 6
C. 0
D. Garbage Value

View Answer


2. What is the output of this program?

void main()
{
int arr[10];
printf("%d %d", arr[-2], arr[11]);
}

A. 0 0
B. Garbage value 0
C. Garbage value Garbage value
D. Compilation Error

View Answer


3. What will be the output of the program if the array begins at 1000 and each integer occupies 2 bytes?

void main()
{
int arr[2][2] = { 1, 2, 3, 4 };
printf("%u, %u", arr+1, &arr+1);
}

A. 1004 1008
B. 1002 1008
C. 1002 1002
D. 1008 1002

View Answer


4. What is the output of this program?

#include<stdio.h>
int main()
{
int arr[5] = {1,2,3,4,5};
int p, q, r;
p = ++arr[1];
q = arr[1]++;
r = arr[p++];
printf("%d, %d, %d", p, q, r);
return 0;
}

A. 3 4 5
B. 3 4 4
C. 4 3 4
D. 4 4 5

View Answer


5. What is the output of this program?

#include<stdio.h>
int main()
{
int a[1]={100};
printf("%d\n", 0[a]);
return 0;
}

A. 100
B. 0
C. Garbage Value
D. Compilation Error

View Answer


6. What is the output of this program? (Assume that base address of a is 1000 and size of integer is 32 bit)
#include>stdio.h<
int main()
{
int a[10];
a++;
printf("%u", a);
return 0;
}

A. 1004
B. 1002
C. 1008
D. Lvalue Required

View Answer


7. Which of the following will print the value 2 for the above code?

#include<stdio.h>
int main()
{
int arr[10][20][30] = {0};
arr[3][2][1] = 2;
return 0;
}

A. printf("%d",*(((a+3)+2)+1));
B. printf("%d",***((a+3)+2)+1);
C. printf("%d",*(*(*(a+3)+2)+1));
D. None of the above

View Answer


8. Which is true about the given statment ?

int arr[10] = {0,1,2,[7]=7,8,9};

A. Compipation Error
B. Run-time Error
C. This is allowed in C
D. None of the above

View Answer


9. What is the output of this program?

#include<stdio.h>
void main(){
char c[] = "GATE2011";
char *p =c;
printf("%s", p + p[3] - p[1]);
}

A. GATE2011
B. E2011
C. 2011
D. 11

View Answer


10. What is the output of this program?

#include<stdio.h>
#include<string.h>
void main()
{ char s1[20] = "Hello", s2[10] = " World";
printf("%s", strcpy(s2, strcat(s1, s2)));
}

A. Hello World
B. HelloWorld
C. Hello
D. World

View Answer


11. How many times the loop will execute ?

#include<stdio.h>
int main()
{
char str[10] = "98765", *p;
p = str + 1;
*p = '0' ;
printf ("%s", str);
}

A. 98
B. 0
C. 98766
D. 90765

View Answer


12. What is the output of this program?

#include<stdio.h>
void main()
{
char s[] = "Letsfind\0course";
printf("%s", str);
}

A. Letsfindcourse
B. Letsfind
C. course
D. Compilation Error

View Answer


13. What is the output of this program?

int main()
{
char str[14] = "Letsfindcourse";
printf("%s\n", str);
return 0;
}

A. Letsfindcours
B. Letsfindcourse
C. Run Time Error
D. Compilation Error

View Answer


14. What is the output of the given code ?

#include<stdio.h>
int main()
{
int i;
char str[] = "\0";
if(printf("%s", str))
printf("Empty String\n");
else
printf("String is not empty\n");
return 0;
}

A. Empty String
B. String is not empty
C. 0
D. None of the above

View Answer


15. What is the output of this program?

#include<stdio.h>
int main()
{
char str = "Hello";
printf("%s\n", str);
return 0;
}

A. Hello
B. Base address of str
C. Segmentation Fault
D. None of the above

View Answer


16. What is the output of this program?

#include<stdio.h>
int main()
{
char s1[] = "Hello";
char s2[] = "Hello";
if(s1 == s2)
printf("Same\n");
else
printf("Not Same\n");
return 0;
}

A. Not Same
B. Same
C. Compilation Error
D. None of the above

View Answer


17.What will be the output of the program ?

#include<stdio.h>
int main(void)
{
char p;
char buf[10]={1,2,3,4,5,6,9,8};
p=(buf+1)[5];
printf("%d",p);
return 0;
}

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

View Answer


18.What will be the output of the program ?

#include<stdio.h>
int main()
{
int a[5]={5,1,15,20,25};
int i,j,m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}

A. 3,2,15
B. 2,3,20
C. 2,1,15
D. 1.2.5

View Answer



Discussion

* You must be logged in to add comment.