C Arrays - Aptitude Questions and Answers

C programming Arrays (One-D Array, Two-D Array) Aptitude Questions and Answers : In this section you will find C Aptitude Questions and Answers on One Dimensional (1D) and Two Dimensional (2D) array.

List of C programming Array (One, Two Dimensional) Aptitude Questions and Answers

1) What will be the output of following program ?
#include <stdio.h>
int main()
{
	static int var[5];
	int count=0;
	
	var[++count]=++count;
	for(count=0;count<5;count++)
		printf("%d ",var[count]);
	
	return 0;
}
  1. 0 1 0 0 0
  2. 0 2 0 0 0
  3. 0 0 2 0 0
  4. 0 0 0 0 0

2) What will be the output of following program ? (for 32 bits compiler)
#include <stdio.h>
int main()
{
	int MAX=10;
	int array[MAX];
	printf("size of array is = %d",sizeof(array);
	return 0;
}
  1. size of array is = 20
  2. size of array is = 40
  3. size of array is = 4
  4. Error

3) What will be the output of following program ?
#include <stdio.h>
#define MAX 10
int main()
{	int array[MAX]={1,2,3},tally;
	for(tally=0;tally< sizeof(array)/sizeof(int);tally+=1)
		printf("%d ",*(tally+array));
	return 0;
}
  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


4) What will be the output of following program ?
#include <stdio.h>
int main()
{	static int x[]={'A','B','C','D','E'},tally;
	for(tally=0;tally< sizeof(x)/sizeof(int) ; tally+=1)
		printf("%c,%c,%c\n",*(x+tally)+1,x[tally]+1,*(tally+x)+1);
	return 0;
}
  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

5) What will be the output of following program ?
#include <stdio.h>
int main()
{	static int array[]={10,20,30,40,50};
	printf("%d...%d",*array,*(array+3)* *array);
	return 0;
}
  1. Error
  2. 10...40
  3. 10...300
  4. 10....400

6) What will be the output of following program ?
#include <stdio.h>
int main()
{	int a[5]={1,2,3,4,5},b[5]={10,20,30,40,50},tally;
	
	for(tally=0;tally< 5;++tally)
		*(a+tally)=*(tally+a)+ *(b+tally);
	
	for(tally=0;tally< 5;tally++)
		printf("%d ",*(a+tally));

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


7) What will be the output of following program ?
#include <stdio.h>
int main()
{	int a[5]={0x00,0x01,0x02,0x03,0x04},i;
	i=4;
	while(a[i])
	{
		printf("%02d  ",*a+i);
		--i;
	}
	return 0;
}
  1. 00 01 02 03 04
  2. 04 03 02 01 00
  3. 04 03 02 01
  4. 01 02 03 04

8) What will be the output of following program ?
#include <stdio.h>
int main()
{
	char X[10]={'A'},i;
	for(i=0; i<10; i++)
		printf("%d ",X[i]);
	return 0;
}
  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

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[];





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.