当前位置:网站首页>C language pointer practice questions

C language pointer practice questions

2022-08-10 01:48:00 BSP Junior Primary School Monk

1. Use the pointer method to calculate the sum of the corresponding positions of each element in the two arrays, and store the result of the sum in the third array, and then output.

#include void count(int *p1,int *p2,int *p3,int x);int main(){int arr01[4]={2,4,5,8};int arr02[4]={1,0,4,6};int arr03[4];count(arr01,arr02,arr03,4);}void count(int *p1,int *p2,int *p3,int x){int i;for(i=0;i

Run result:

2. Using the pointer, output the alphabet in sequence, and then output in reverse order.

#include #include int main(){char *p01=(char *) malloc(sizeof(char)*26);char *p02=(char *) malloc(sizeof(char)*26);int i;printf("Output in uppercase alphabetical order:\n");for(i=0;i<26;i++){*(p01+i)=('A'+i);printf("%c ",*(p01+i));}printf("\n\n");printf("Output in lowercase alphabetical order:\n");for(i=0;i<26;i++){*(p02+i)=('a'+i);printf("%c ",*(p02+i));}printf("\n\n");printf("Reverse uppercase letters:\n");for(i=25;i>=0;i--){printf("%c ",*(p01+i));}printf("\n\n");printf("Reverse lowercase output:\n");for(i=25;i>=0;i--){printf("%c ",*(p02+i));}return 0;} 

Run result:

原网站

版权声明
本文为[BSP Junior Primary School Monk]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/222/202208092342344318.html