c语言数组-1
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.
C编程数组(一维数组,二维数组)能力问题:在本节中,您将找到关于一维(1D)和二维(2D)数组的C能力问题。
C编程数组(一维,二维)智能问题列表 (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;
}
Answer
Correct Answer - 3
0 0 2 0 0
0 0 2 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;
}
Answer
Correct Answer - 2
size of array is = 40
size of array is = 40
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;
}
Answer
Correct Answer - 3
1 2 3 0 0 0 0 0 0 0.
You can also access the array elements using *(counter_variable+array_name).
1 2 3 0 0 0 0 0 0 0.
You can also access the array elements using *(counter_variable+array_name).
3)以下程序的输出是什么?
回答
正确答案-3
1 2 3 0 0 0 0 0 0 0。
您还可以使用 *(counter_variable + array_name)访问数组元素。
1 2 3 0 0 0 0 0 0 0。
您还可以使用 *(counter_variable + array_name)访问数组元素。
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;
}
Answer
Correct Answer - 3
B,B,B
C,C,C
D,D,D
E,E,E
F,F,F
B,B,B
C,C,C
D,D,D
E,E,E
F,F,F
4)以下程序的输出是什么?
回答
正确答案-3
B,B,B
C,C,C
D,D,D
E,E,E
F,F,F
B,B,B
C,C,C
D,D,D
E,E,E
F,F,F
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;
}
Answer
Correct Answer - 4
10...400
In expression printf("%d...%d",*array,*(array+3)* *array);, *array is 10, *(array+3) is 40.
10...400
In expression printf("%d...%d",*array,*(array+3)* *array);, *array is 10, *(array+3) is 40.
5)以下程序的输出是什么?
回答
正确答案-4
10 ... 400
在表达式中 printf(“%d ...%d”,* array,*(array + 3)* * array); ,* array是 10 ,*(array + 3)是 40 。
10 ... 400
在表达式中 printf(“%d ...%d”,* array,*(array + 3)* * array); ,* array是 10 ,*(array + 3)是 40 。
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;
}
Answer
Correct Answer - 3
11 22 33 44 55
This is a simple program to add elements of two arrays, you can access array elements using *(tally+a) Or *(b+tally) Or a[tally] .
11 22 33 44 55
This is a simple program to add elements of two arrays, you can access array elements using *(tally+a) Or *(b+tally) Or a[tally] .
6)以下程序的输出是什么?
回答
正确答案-3
11 22 33 44 55
这是一个添加两个数组元素的简单程序,您可以使用 *(tally + a)或*(b + tally)或a [tally]访问数组元素。
11 22 33 44 55
这是一个添加两个数组元素的简单程序,您可以使用 *(tally + a)或*(b + tally)或a [tally]访问数组元素。
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;
}
Answer
Correct Answer - 3
04 03 02 01
0x00,0x01,0x02,0x03,0x04,0x05 are hex values of 0,1,2,3,4,5.
while(a[i]) will be terminated by a[0], becuase value of a[0] is 0 hence, 04,03,03,01 will print.
04 03 02 01
0x00,0x01,0x02,0x03,0x04,0x05 are hex values of 0,1,2,3,4,5.
while(a[i]) will be terminated by a[0], becuase value of a[0] is 0 hence, 04,03,03,01 will print.
7)以下程序的输出是什么?
回答
正确答案-3
04 03 02 01
0x00,0x01,0x02,0x03,0x04,0x05是十六进制值0、1、2、3、4、5。
while(a [i])将以a [0]终止,因为a [0]的值为0,因此将打印04、03、03、01。
04 03 02 01
0x00,0x01,0x02,0x03,0x04,0x05是十六进制值0、1、2、3、4、5。
while(a [i])将以a [0]终止,因为a [0]的值为0,因此将打印04、03、03、01。
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;
}
Answer
Correct Answer - 1
A 0 0 0 0 0 0 0 0 0
char X[10]={'A'}; 0 th index of X is assigned by 'A' and rest of elements is assigned by 0.
A 0 0 0 0 0 0 0 0 0
char X[10]={'A'}; 0 th index of X is assigned by 'A' and rest of elements is assigned by 0.
8)以下程序的输出是什么?
回答
正确答案-1
A 0 0 0 0 0 0 0 0 0
字符X [10] = {'A'}; X的 第 0 个索引由“ A”分配,其余元素由0分配。
A 0 0 0 0 0 0 0 0 0
字符X [10] = {'A'}; X的 第 0 个索引由“ A”分配,其余元素由0分配。
9) Which is an incorrect declaration of one dimensional array ?
Answer
Correct Answer - 4
int x[];
You can ignore value within the subscript [] when you are initialising array with elements, but here no initialisation found.
9)哪个是一维数组的不正确声明?
回答
正确答案-4
int x [];
当您使用元素初始化数组时,可以忽略下标[]中的值,但是在此找不到初始化。
翻译自: https://www.includehelp.com/c-programs/c-arrays-aptitude-questions-and-answers.aspx
c语言数组-1