• Learning c section 1


    #include<stdio.h>
    
    void main()
    {
    	puts("hello world");
    	int x=4;
    	//the %p format will print out the location in hex(base lb) format
    	printf("x lives at %p
    ",&x);
    	int * addr_of_x = &x;
    	printf("x lives at %p
    ",addr_of_x);
    	printf("the content of addr_of_x is %d
    ",*addr_of_x);	
    	
    	printf("the size of int is %d
    ",sizeof(int));
    	char quote[]="turtles!";
    	// this will return 9, which is 8 characters plus the  end character
    	printf("the size of int is %d
    ",sizeof(quote));
    	//why pointers have types?
    	/**
    		different data types has different size, when you do pointer arithmetic,
    		the compiler will not know how to increce the value when you not specify 
    		the concrete data type of the pointer.
    	**/
    	int doses[] = {1, 3, 2, 1000};
    	printf("Issue dose %i
    ", 3[doses]);
    	/*
    	char name[40];
    	printf("Enter your name: ");
    	scanf("%39s",name);
    	printf("your name is :%s
    ",name);
    	int age;
    	printf("Enter your age: ");
    	scanf("%i
    ", &age);
    	printf("your age is :%i
    ",age);
    	//be careful with this , if your input is bigger than your variable to hold it.
    	//it will cause buffer overflows
    	char food[5];
    	printf("Enter favorite food: ");
    	fgets(food, sizeof(food), stdin);
    	printf("your favorite food is :%s
    ",food);
    	*/
    	char *cards="JQK";
    	//string literals can never be updated 
    	//the following code will cause one error,
    	//but it will pass compile 
    	//why cause this? the string literals will store one read only memory.
    	//these constants will be used all threads, so can not changed.
    	//cards[1]='K'; 
    	puts(cards);
    	printf("address of the cards is :%p
    ",cards);
    	printf("address of the string JQK is :%p
    ",&"JQK");
    	char cards2[]="JQK";
    	puts(cards2);
    	printf("address of the cards is :%p
    ",cards2);
    
    }
    refer: head first C
    Looking for a job working at Home about MSBI
  • 相关阅读:
    列表的内置方法
    oracle安装教程
    大二暑假假期周进度01
    win 10安装Linux虚拟机教程
    需求工程——软件建模与分析阅读笔记05
    网络爬虫阅读笔记01
    Java 测试连接Oracle数据库是否成功,ojdbc7.jar包下载
    河北创新年报统计平台系统整体界面展示,与数据下钻
    java 三大框架 struct2部分 实现增删该查操作
    itextsharp生成pdf
  • 原文地址:https://www.cnblogs.com/huaxiaoyao/p/4375555.html
Copyright © 2020-2023  润新知