编写一个C程序,演示指针的示例

2023年 9月 21日 90.2k 0

#include
void main(){
//Declaring variables and pointer//
int a=2;
int *p;
//Declaring relation between variable and pointer//
p=&a;
//Printing required example statements//
printf("Size of the integer is %d

",sizeof (int));//4//
printf("Address of %d is %d

",a,p);//Address value//
printf("Value of %d is %d

",a,*p);//2//
printf("Value of next address location of %d is %d

",a,*(p+1));//Garbage value from (p+1) address//
printf("Address of next address location of %d is %d

",a,(p+1));//Address value +4//
//Typecasting the pointer//
//Initializing and declaring character data type//
//a=2 = 00000000 00000000 00000000 00000010//
char *p0;
p0=(char*)p;
//Printing required statements//
printf("Size of the character is %d

",sizeof(char));//1//
printf("Address of %d is %d

",a,p0);//Address Value(p)//
printf("Value of %d is %d

",a,*p0);//First byte of value a - 2//
printf("Value of next address location of %d is %d

",a,*(p0+1));//Second byte of value a - 0//
printf("Address of next address location of %d is %d

",a,(p0+1));//Address value(p)+1//
}

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论