You are on page 1of 7

14.04.

2015

learnxinyminutes.com/docs/files/learncru.c

////99.
/*
.89.
*/
//**#include**
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
//<>.
//"".
#include"my_header.h"
//.h.c.
voidfunction_1();
voidfunction_2();
//main.
intmain(){
//printf
//%d,,\n
//
printf("%d\n",0);//=>"0"
//.
///////////////////////////////////////
//
///////////////////////////////////////
//int4
intx_int=0;
//short2
shortx_short=0;
//char1
charx_char=0;
chary_char='y';//''
//long48
//longlong64
longx_long=0;
longlongx_long_long=0;
//float32
floatx_float=0.0;
//double64
doublex_double=0.0;
//.
unsignedshortux_short;
unsignedintux_int;
unsignedlonglongux_long_long;
//sizeof(T).
//sizeof(obj)obj.
printf("%zu\n",sizeof(int));//=>4(int4)
//sizeof,
//().
http://learnxinyminutes.com/docs/files/learncru.c

1/7

14.04.2015

learnxinyminutes.com/docs/files/learncru.c

inta=1;
//size_t2
//
size_tsize=sizeof(a++);//a++
printf("sizeof(a++)=%zu,a=%d\n",size,a);
//"sizeof(a++)=4,a=1"(32)
//.
charmy_char_array[20];//1*20=20
intmy_int_array[20];//4*20=80(4)
//.
charmy_array[20]={0};
//.
my_array[0];//=>0
//..
my_array[1]=2;
printf("%d\n",my_array[1]);//=>2
//C99(C11),.
//.
printf("Enterthearraysize:");//
charbuf[0x100];
fgets(buf,sizeofbuf,stdin);
size_tsize=strtoul(buf,NULL,10);//strtoul
intvar_length_array[size];//
printf("sizeofarray=%zu\n",sizeofvar_length_array);
//():
//>Enterthearraysize:10
//>sizeofarray=40
//,(NUL(0x00))
//'\0'.
//,
//.
chara_string[20]="Thisisastring";
printf("%s\n",a_string);//%s
printf("%d\n",a_string[16]);//=>0
//#170(18,19,20)
//,
//int,char().

intcha='a';//
charchb='a';//(intchar)
///////////////////////////////////////
//
///////////////////////////////////////
//.
inti1=1,i2=2;
floatf1=1.0,f2=2.0;
//
i1+i2;//=>3
i2i1;//=>1
i2*i1;//=>2
i1/i2;//=>0(0.5,0)
f1/f2;//=>0.5,,
//!
http://learnxinyminutes.com/docs/files/learncru.c

2/7

14.04.2015

learnxinyminutes.com/docs/files/learncru.c

//
11%3;//=>2
//,.
//int.0false,true.
//10.
3==2;//=>0(false)
3!=2;//=>1(true)
3>2;//=>1
3<2;//=>0
2<=2;//=>1
2>=2;//=>1
//.
inta=1;
//:
intbetween_0_and_2=0<a<2;
//:
intbetween_0_and_2=0<a&&a<2;
//
!3;//=>0()
!0;//=>1
1&&1;//=>1()
0&&1;//=>0
0||1;//=>1()
0||0;//=>0
//
~0x0F;//=>0xF0()
0x0F&0xF0;//=>0x00()
0x0F|0xF0;//=>0xFF()
0x04^0x0F;//=>0x0B((XOR))
0x01<<1;//=>0x02((1))
0x02>>1;//=>0x01((1))
//int,:
//(inta=1<<32)
//(inta=1<<2)
///////////////////////////////////////
//
///////////////////////////////////////
//
if(0){
printf("Iamneverrun\n");
}elseif(0){
printf("Iamalsoneverrun\n");
}else{
printf("Iprint\n");
}
//
intii=0;
while(ii<10){
printf("%d,",ii++);//
//ii("postincrement")
}//=>prints"0,1,2,3,4,5,6,7,8,9,"
printf("\n");

//
intkk=0;
http://learnxinyminutes.com/docs/files/learncru.c

3/7

14.04.2015

learnxinyminutes.com/docs/files/learncru.c

do{
printf("%d,",kk);
}while(++kk<10);//
//kk("preincrement")
//=>prints"0,1,2,3,4,5,6,7,8,9,"
printf("\n");
//
intjj;
for(jj=0;jj<10;jj++){
printf("%d,",jj);
}//=>prints"0,1,2,3,4,5,6,7,8,9,"
printf("\n");
//
switch(some_integral_expression){
case0://()
do_stuff();
break;//break;
case1:
do_something_else();
break;
default:
//,default:
fputs("!\n",stderr);
exit(1);
break;
}

///////////////////////////////////////
//
///////////////////////////////////////
//,,
//().
intx_hex=0x01;//.
//.
printf("%d\n",x_hex);//=>Prints1
printf("%d\n",(short)x_hex);//=>Prints1
printf("%d\n",(char)x_hex);//=>Prints1
//.
printf("%d\n",(unsignedchar)257);//=>1(Maxchar=255ifcharis8bitslong)
//`char`,`signedchar``unisigned
char`,
//CHAR_MAX,SCHAR_MAXUCHAR_MAX<limits.h>

//.
printf("%f\n",(float)100);//%fformatsafloat
printf("%lf\n",(double)100);//%lfformatsadouble
printf("%d\n",(char)100.0);
///////////////////////////////////////
//
///////////////////////////////////////
//.
//
.
//,.
http://learnxinyminutes.com/docs/files/learncru.c

4/7

14.04.2015

learnxinyminutes.com/docs/files/learncru.c

//&.
intx=0;
printf("%p\n",(void*)&x);//=>,x
//(%pvoid*)
//*.
int*px,not_a_pointer;//pxint
px=&x;//xpx
printf("%p\n",(void*)px);//=>,px
printf("%zu,%zu\n",sizeof(px),sizeof(not_a_pointer));
//=>"8,4"64
//,,*.
//,*
//,.
printf("%d\n",*px);//=>0,x
//,.
(*px)++;//px
printf("%d\n",*px);//=>1
printf("%d\n",x);//=>1
//.
intx_array[20];
intxx;
for(xx=0;xx<20;xx++){
x_array[xx]=20xx;
}//x_array20,19,18,...2,1
//int.
int*x_ptr=x_array;
//x_ptr(20).
//,.
//,,
//.
//:'&':
intarr[10];
int(*ptr_to_arr)[10]=&arr;//&arr'int*'!
//""(
'int').
//,:
chararr[]="foobarbazquirk";
//`sizeof``alignof`:
intarr[10];
int*ptr=arr;//"int*ptr=&arr[0];"
printf("%zu%zu\n",sizeofarr,sizeofptr);//"40,4""40,8"
//
//()
printf("%d\n",*(x_ptr+1));//=>19
printf("%d\n",x_array[1]);//=>19
//
//malloc,
//size_t.
int*my_ptr=malloc(sizeof(*my_ptr)*20);
for(xx=0;xx<20;xx++){
*(my_ptr+xx)=20xx;//my_ptr[xx]=20xx
}//20,19,18,17...2,1(int')
//
//.
printf("%d\n",*(my_ptr+21));//=>?
//.
http://learnxinyminutes.com/docs/files/learncru.c

5/7

14.04.2015

learnxinyminutes.com/docs/files/learncru.c

//,,
//,.
free(my_ptr);
//,
//().
//`constchar*'
//..
//("foo"[0]='a'!)
constchar*my_str="Thisismyveryownstringliteral";
printf("%c\n",*my_str);//=>'T'
//,
//()
//:
charfoo[]="foo";
foo[0]='a';//"aoo"
voidfunction_1()
}//main()
///////////////////////////////////////
//
///////////////////////////////////////
//:
//<><>()
intadd_two_ints(intx1,intx2){
returnx1+x2;//return
}
/*
"",
.
:
*/
//void,
voidstr_reverse(char*str_in){
chartmp;
intii=0;
size_tlen=strlen(str_in);//`strlen()`
for(ii=0;ii<len/2;ii++){
tmp=str_in[ii];
str_in[ii]=str_in[lenii1];//ii
str_in[lenii1]=tmp;
}
}
charc[]="Thisisatest.";
str_reverse(c);
printf("%s\n",c);//=>".tsetasisihT"
///////////////////////////////////////
//
///////////////////////////////////////
//typedef
typedefintmy_type;
my_typemy_type_var=0;
http://learnxinyminutes.com/docs/files/learncru.c

6/7

14.04.2015

learnxinyminutes.com/docs/files/learncru.c

//,,
//.
structrectangle{
intwidth;
intheight;
};
//sizeof(structrectangle)==sizeof(int)+sizeof(int)
//()[1].
voidfunction_1(){
structrectanglemy_rec;
//
my_rec.width=10;
my_rec.height=20;
//
structrectangle*my_rec_ptr=&my_rec;
//
(*my_rec_ptr).width=30;
//...:>
my_rec_ptr>height=10;//"(*my_rec_ptr).height=10;"
}
//typedef,.
typedefstructrectanglerect;
intarea(rectr){
returnr.width*r.height;
}
//,"",
//.
intarea(constrect*r){
returnr>width*r>height;
}
///////////////////////////////////////
//
///////////////////////////////////////
/*
.
.
.
:str_reverse
*/
voidstr_reverse_through_pointer(char*str_in){
//.
void(*f)(char*);//.
f=&str_reverse;//()
//"f=str_reverse;".
//().
(*f)(str_in);//.
//"f(str_in);"
}

http://learnxinyminutes.com/docs/files/learncru.c

7/7