Presentation is loading. Please wait.

Presentation is loading. Please wait.

The little language that could Remember C is a “small language”

Similar presentations


Presentation on theme: "The little language that could Remember C is a “small language”"— Presentation transcript:

1 The little language that could Remember C is a “small language”

2 32 “keywords”

3 Note... No input or output statements No mathematical functions No “strings” No “Boolean” type C is “case sensitive” (A is not equal to a) Everything else is done with libraries

4 Basic C data types Five base types –int –char –float –enum –void

5 And one more... Pointers to the five basic types –Pointers are everything in C. –Arrays, “strings”, complex types use pointers

6 int Integer values (0,1,2,3…) “signed” versus “unsigned” “short”(16 bit) versus “long” (32 bit) Can use decimal, octal (015) or hexadecimal (0xff) Something to note... –10000+20000+40000=4464? (short int)

7 char Character values (‘a’,’b’,’c’…) Can also be used as “small” integers The way to access “bytes” on the machine

8 float The “floating point” numbers (IEEE) Different levels of precision –float (6 digits of precision [ 1.17 x 10 -38 to 3.40 x 10 38 ] –double(15 digits of precision) [2.22x10 -308 to 1.79x10 308 ] –long double (80 digits of precision) 5.7, 500.234, 5.7e-3,-2.73e2

9 enum The “enumerated” type enum {U,M,T,W,R,F,S} dayofweek; Converted to numbers but can use symbols

10 void The “nothing” type Used for pointers and when you don’t want to return anything

11 The “Hello World” Program

12 How to compile a C program Use the “gcc” command –gcc test.c –gcc -o test1 test1.c (CAREFUL!!!)

13 How to run a C program If you don’t use the ‘-o’ option, just type “./a.out” If you do, type “./test1” or whatever the name is.

14 Style Comments in C use /* */ Indenting is good. Use “good variable names”. Show some style in your programs.

15 printf The way to get data out of a C program. General format: printf(format,variable…); –printf(“Value for ia = %d\n”,ia); –printf(“Value for fx = %f\n”,fx); –printf(“The character is %c\n”,ch);

16 scanf This one will definitely “bake your biscuits” Requires the use of a pointer –scanf(“%d”,&ia); –scanf(“%f”,&fx); –scanf(“%c”,&ch); –EXCEPT scanf(“%s”,mystr); {if char mystr[20]}

17 “Standard I/O” Three “standard” files opened with every program –stdin –stdout –stderr

18 f Stuff fscanf(stdin,”%d”,&answer) fprintf(stdout,”My answer is %d\n”,answer) fprintf(stderr,”Error!\n”)

19 And two more FILE *input,*output; input=fopen(“./input.dat”,”r”); output=fopen(“./output.dat”,”w”); fclose(input); fclose(output);


Download ppt "The little language that could Remember C is a “small language”"

Similar presentations


Ads by Google