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
原文地址:https://www.cnblogs.com/huaxiaoyao/p/4375555.html