其他分享
首页 > 其他分享> > C语言学习记录_2019.02.09

C语言学习记录_2019.02.09

作者:互联网

struct
    {
        int amount;
        char *name;
    }coins[] = 
    {
    {1,"one"},
    {2,"two"},
    {3,"three"}
    };

    char *abc="zxcvbnm";
    printf("%s\n",coins[2].name);
    printf("%s",abc);

 

char s1[]="array";  //字符数组

char s2[6]="array";  //数组长度=字符串长度+1,因为字符串末尾会自动添‘\0‘

printf("%s,%c\n",s1,s2[2]);  //array,r
char *sp="pointer";  //字符指针

printf("%s,%c,%c\n",sp,*sp,*(sp+2));  //pointer,p,i
char s1[6];    

scanf("%s\n",s1);

printf("%s,%c\n",s1,s1[2]);  //array,r
char str[60], *sp=str;//将数组的首地址str赋给指针变量sp

scanf("%s\n",sp);

printf("%s,%c,%c\n",sp,*sp,*(sp+3));//pointer,p,n

printf("%s,%c,%c\n",str,str[0],str[3]);//pointer,p,n
#include<stdio.h>
struct student
{
    int num;
    char name[10];
};
void main()
{
    struct student s;
    printf("输入学号:\n");
    scanf("%d",&s.num);//scanf赋值给结构体的num成员
    printf("输入姓名:\n");
    scanf("%s",&s.name);
    printf("输入的信息为:学号:%d,姓名:%s\n",s.num ,s.name);
}

标签:09,scanf,2019.02,C语言,char,str,printf,s1,sp
来源: https://www.cnblogs.com/Bran-don/p/10358433.html