



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A Quick Reference to C Programming Language
Typology: Cheat Sheet
1 / 7
This page cannot be seen from the preview
Don't miss anything!




#include(stdio.h) /* include IO library / #include... / include other files / #define.. / define constants */
/* Declare global variables*/) (variable type)(variable list);
/* Define program functions */ (type returned)(function name)(parameter list) (declaration of parameter types) { (declaration of local variables); (body of function code); } /* Define main function*/ main ((optional argc and argv arguments)) (optional declaration parameters) { (declaration of local variables); (body of main function code); }
Format: /(body of comment) / Example: /This is a comment in C/
Format: #define(constant name)(constant value) Example: #define MAXIMUM 1000
Format: typedef(datatype)(symbolic name); Example: typedef int KILOGRAMS;
Declarations: Format: (variable type)(name 1)(name 2),...; Example: int firstnum, secondnum;
char alpha; int firstarray[10]; int doublearray[2][5]; char firststring[1O];
Initializing: Format: (variable type)(name)=(value); Example: int firstnum=5;
Assignments: Format: (name)=(value); Example: firstnum=5; Alpha='a';
Declarations: Format: union(tag) {(type)(member name); (type)(member name); ... }(variable name); Example: union demotagname {int a; float b; }demovarname;
Assignment: Format: (tag).(member name)=(value); demovarname.a=1; demovarname.b=4.6;
Declarations: Format: struct(tag) {(type)(variable); (type)(variable); ... }(variable list);
{int idnum; int finalgrade; char lettergrade; } first,second,third;
%h hex %e exponential %f float %g shorter of %e or %f %c char %s string Print Escape Sequences: \n newline \t tab \r carriage return \f form feed \b backspace ' output \ output \
Input: Scanf Format: scanf("(conversion specs)",&(varl),&(var2),...);
Scanf Example: scanf("%d %d %d",&first,&second,&third);
Scanf Conversion Specifications: %d decimal integer expected %o octalinteger expected %x hex integer expected %h short integer expected %c character expected %s string expected %r real value expected %e exponential notation expected
Primitive Input and Output Examples: Get a character from standard input: c = getchar(); Put a character on standard output: putcher(c);
for ((first expr);(second expr);(third expr)) (simple statement); for ((first expr);(second expr);(third expr)) { (compound statement);
WHILE LOOP Format: while ((condition)) (simple statement); while ((condition)) { (compound statement); } DO WHILE LOOP Format: do (simple statement)' while ((condition)) do { (compound statement); } while ((condition));
IF CONDITIONAL Format: if ((condition)) (simple statement); if ((condition)) { (compound statement); }
IF... ELSE CONDITIONAL Format: if ((condition)) (statement 1); else (statement 2); SWITCH Format: switch ((expression)) {case (value 1):(statement 1); case (value 2):(statement 2); ... default:(default statement); }
Format: (type returned)(function name)((parameter list)) (declaration of parameter list variables) {