c语言数组-1_C数组-智能问题与解答

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;
}
  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
Correct Answer - 3
0 0 2 0 0
1)以下程序的输出是什么?
  1. 0 1 0 0 0

  2. 0 2 0 0 0

  3. 0 0 2 0 0

  4. 0 0 0 0 0

回答
正确答案-3
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;
}

  1. size of array is = 20

  2. size of array is = 40

  3. size of array is = 4

  4. Error

Answer
Correct Answer - 2
size of array is = 40
2)以下程序的输出是什么? (用于32位编译器)
  1. 数组的大小= 20

  2. 数组的大小是= 40

  3. 数组的大小为= 4

  4. 错误

回答
正确答案-2
数组的大小是= 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;
}

  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
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).
3)以下程序的输出是什么?
  1. 错误

  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

回答
正确答案-3
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;
}

  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
Correct Answer - 3
B,B,B
C,C,C
D,D,D
E,E,E
F,F,F

4)以下程序的输出是什么?
  1. 错误

  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

回答
正确答案-3
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;
}

  1. Error

  2. 10...40

  3. 10...300

  4. 10....400

Answer
Correct Answer - 4
10...400
In expression printf("%d...%d",*array,*(array+3)* *array);, *array is 10, *(array+3) is 40.
5)以下程序的输出是什么?
  1. 错误

  2. 10 ... 40

  3. 10 ... 300

  4. 10 .... 400

回答
正确答案-4
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;
}

  1. 1 2 3 4 5

  2. 10 20 30 40 50

  3. 11 22 33 44 55

  4. Error

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] .
6)以下程序的输出是什么?
  1. 1 2 3 4 5

  2. 10 20 30 40 50

  3. 11 22 33 44 55

  4. 错误

回答
正确答案-3
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;
}
  1. 00 01 02 03 04

  2. 04 03 02 01 00

  3. 04 03 02 01

  4. 01 02 03 04

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.
7)以下程序的输出是什么?
  1. 00 01 02 03 04

  2. 04 03 02 01 00

  3. 04 03 02 01

  4. 01 02 03 04

回答
正确答案-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。
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

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.
8)以下程序的输出是什么?
  1. A 0 0 0 0 0 0 0 0 0

  2. 一个

  3. A 32 32 32 32 32 32 32 32 32

  4. 错误

回答
正确答案-1
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 ?
  1. int x[5];

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

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

  4. int x[];

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)哪个是一维数组的不正确声明?
  1. int x [5];

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

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

  4. int x [];

回答
正确答案-4

int x [];
当您使用元素初始化数组时,可以忽略下标[]中的值,但是在此找不到初始化。

翻译自: https://www.includehelp.com/c-programs/c-arrays-aptitude-questions-and-answers.aspx

c语言数组-1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值