c语言用指针定义一个类型进行输入输出


1 整型数组

//

#include "stdafx.h"
#include "stdlib.h"

int _tmain(int argc, _TCHAR* argv[])
{
int *q=(int*)malloc(sizeof(int)*5);   //malloc函数动态分配5个整型数的地址空间。

printf("Please input:");

for(int i=0;i<5;i++)

scanf("%d",q+i);  

for(int i=0;i<5;i++) 
 
printf("%d ",*(q+i));
    system("pause");
    return 0;
}

2 定义有一个字符串进行输入输出

#include "stdafx.h"
#include "stdlib.h"

int _tmain(int argc, _TCHAR* argv[])
{
char *str=(char*)malloc(100);   //malloc函数动态分配地址空间。

printf("Please input:");

scanf("%s",str);   


printf("%s",str);   //注意 不用加 *
    system("pause"); 
    return 0;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM