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)
#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;
}
0 1 0 0 0
0 2 0 0 0
0 0 2 0 0
0 0 0 0 0
0 0 2 0 0
0 1 0 0 0
0 2 0 0 0
0 0 2 0 0
0 0 0 0 0
0 0 2 0 0
#include <stdio.h>
int main()
{
int MAX=10;
int array[MAX];
printf("size of array is = %d",sizeof(array);
return 0;
}
size of array is = 20
size of array is = 40
size of array is = 4
Error
size of array is = 40
數組的大小= 20
數組的大小是= 40
數組的大小為= 4
錯誤
數組的大小是= 40
#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;
}
Error
1 3 4 5 6 7 8 9 10 11
1 2 3 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 2 3 0 0 0 0 0 0 0.
You can also access the array elements using *(counter_variable+array_name).
錯誤
1 3 4 5 6 7 8 9 10 11
1 2 3 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 2 3 0 0 0 0 0 0 0。
您還可以使用*(counter_variable + array_name)訪問數組元素。
#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;
}
Error
A,A,A
B,B,B
C,C,C
D,D,D
E,E,EB,B,B
C,C,C
D,D,D
E,E,E
F,F,FE,E,E
D,D,D
C,C,C
B,B,B
A,A,A
B,B,B
C,C,C
D,D,D
E,E,E
F,F,F
錯誤
A,A,A
B,B,B
C,C,C
D,D,D
E,E,EB,B,B
C,C,C
D,D,D
E,E,E
F,F,FE,E,E
D,D,D
C,C,C
B,B,B
A,A,A
B,B,B
C,C,C
D,D,D
E,E,E
F,F,F
#include <stdio.h>
int main()
{ static int array[]={10,20,30,40,50};
printf("%d...%d",*array,*(array+3)* *array);
return 0;
}
Error
10...40
10...300
10....400
10...400
In expression printf("%d...%d",*array,*(array+3)* *array);, *array is 10, *(array+3) is 40.
錯誤
10 ... 40
10 ... 300
10 .... 400
10 ... 400
在表達式中printf(“%d ...%d”,* array,*(array + 3)* * array); ,* array是10 ,*(array + 3)是40 。
#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 2 3 4 5
10 20 30 40 50
11 22 33 44 55
Error
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] .
1 2 3 4 5
10 20 30 40 50
11 22 33 44 55
錯誤
11 22 33 44 55
這是一個添加兩個數組元素的簡單程序,您可以使用*(tally + a)或*(b + tally)或a [tally]訪問數組元素。
#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;
}
00 01 02 03 04
04 03 02 01 00
04 03 02 01
01 02 03 04
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.
00 01 02 03 04
04 03 02 01 00
04 03 02 01
01 02 03 04
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。
#include <stdio.h>
int main()
{
char X[10]={'A'},i;
for(i=0; i<10; i++)
printf("%d ",X[i]);
return 0;
}
A 0 0 0 0 0 0 0 0 0
A
A 32 32 32 32 32 32 32 32 32
ERROR
A 0 0 0 0 0 0 0 0 0
char X[10]={'A'}; 0th 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
一個
A 32 32 32 32 32 32 32 32 32
錯誤
A 0 0 0 0 0 0 0 0 0
字符X [10] = {'A'}; X的第 0 個索引由“ A”分配,其余元素由0分配。
int x[5];
int x[5]={1,2,3,4,5};
int x[5]={1,2};
int x[];
int x[];
You can ignore value within the subscript [] when you are initialising array with elements, but here no initialisation found.
int x [5];
int x [5] = {1,2,3,4,5};
int x [5] = {1,2};
int x [];
int x [];
當您使用元素初始化數組時,可以忽略下標[]中的值,但是在此找不到初始化。
翻譯自: https://www.includehelp.com/c-programs/c-arrays-aptitude-questions-and-answers.aspx
c語言數組-1