0% found this document useful (0 votes)
17 views

C Arrays

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

C Arrays

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1) What will be the output of following program ?

1 #include <stdio.h>
2 int main()
3 {
4 static int var[5];
5 int count=0;
6
7 var[++count]=++count;
8 for(count=0;count<5;count++)
9 printf("%d ",var[count]);
10
11 return 0;
12 }

1. 0 1 0 0 0
2. 0 2 0 0 0
3. 0 0 2 0 0
4. 0 0 0 0 0

Answer

2) What will be the output of following program ? (for 32 bits compiler)

1 #include <stdio.h>
2 int main()
3 {
4 int MAX=10;
5 int array[MAX];
6 printf("size of array is = %d",sizeof(array);
7 return 0;
8 }

1. size of array is = 20
2. size of array is = 40
3. size of array is = 4
4. Error

Answer

3) What will be the output of following program ?

1 #include <stdio.h>
2 #define MAX 10
3 int main()
4 { int array[MAX]={1,2,3},tally;
5 for(tally=0;tally< sizeof(array)/sizeof(int);tally+=1)
6 printf("%d ",*(tally+array));
7 return 0;
8 }
/
1. Error
2. 1 3 4 5 6 7 8 9 10 11
3. 1 2 3 0 0 0 0 0 0 0
4. 0 0 0 0 0 0 0 0 0 0

Answer

4) What will be the output of following program ?

1 #include <stdio.h>
2 int main()
3 { static int x[]={'A','B','C','D','E'},tally;
4 for(tally=0;tally< sizeof(x)/sizeof(int) ; tally+=1)
5 printf("%c,%c,%c\n",*(x+tally)+1,x[tally]+1,*(tally+x)+1);
6 return 0;
7 }

1. Error
2. A,A,A
B,B,B
C,C,C
D,D,D
E,E,E
3. B,B,B
C,C,C
D,D,D
E,E,E
F,F,F
4. E,E,E
D,D,D
C,C,C
B,B,B
A,A,A

Answer

5) What will be the output of following program ?

1 #include <stdio.h>
2 int main()
3 { static int array[]={10,20,30,40,50};
4 printf("%d...%d",*array,*(array+3)* *array);
5 return 0;
6 }

1. Error
/
2. 10...40
3. 10...300
4. 10....400

Answer

6) What will be the output of following program ?

1 #include <stdio.h>
2 int main()
3 { int a[5]={1,2,3,4,5},b[5]={10,20,30,40,50},tally;
4
5 for(tally=0;tally< 5;++tally)
6 *(a+tally)=*(tally+a)+ *(b+tally);
7
8 for(tally=0;tally< 5;tally++)
9 printf("%d ",*(a+tally));
10
11 return 0;
12 }

1. 1 2 3 4 5
2. 10 20 30 40 50
3. 11 22 33 44 55
4. Error

Answer

7) What will be the output of following program ?

1 #include <stdio.h>
2 int main()
3 { int a[5]={0x00,0x01,0x02,0x03,0x04},i;
4 i=4;
5 while(a[i])
6 {
7 printf("%02d ",*a+i);
8 --i;
9 }
10 return 0;
11 }

1. 00 01 02 03 04
2. 04 03 02 01 00
3. 04 03 02 01
4. 01 02 03 04

/
Answer

8) What will be the output of following program ?

1 #include <stdio.h>
2 int main()
3 {
4 char X[10]={'A'},i;
5 for(i=0; i<10; i++)
6 printf("%d ",X[i]);
7 return 0;
8 }

1. A 0 0 0 0 0 0 0 0 0
2. A
3. A 32 32 32 32 32 32 32 32 32
4. ERROR

Answer

9) Which is an incorrect declaration of one dimensional array ?

1. int x[5];
2. int x[5]={1,2,3,4,5};
3. int x[5]={1,2};
4. int x[];

Answer

You might also like