CProgramming Cheatsheet
CProgramming Cheatsheet
A variable is an entity whose value may int, float, double and char
or may not change during the program
APTUTS
execution DATA TYPE SIZE
For 32-bit C compiler,
WHAT IS CONSTANT int occupies 4 bytes of memory space
A constant is an entity whose value float occupies 4 bytes of memory space
CONTROL INSTRUCTION
int main() /* 1st block of code */
{ } else {
Control instructions in C are used to alter /* 2nd block of code */
// program body
the logical flow of program execution. }
return 0;
}
if statement If condition is true, execute 1st block of code
Syntax } while(condition); }
switch(expression) {
case constant 1: Here, the block of statement after the The for loop in C is executed as follows:
//perform this; keyword "do" is executed at least once. After
case constant 2: the execution of block of statement for the Step 1: The initial counter value is initialized.
//perform this; first time, the condition in the "while" is This initialization is done only once for the
. evaluated. entire for loop
.
. Block of statement will be repeated until Step 2: Test condition is checked. Test
condition evaluates to false condition can be any relational or logical
default: expression. If the test condition is satisfied
//perform this i.e. the condition evaluates to true then the
} BREAK STATEMENT block of statement inside the for loop is
executed
The break statement is used to break from
any kind of loop and switch statement
WHILE LOOP Step 3: After the execution of the block of
statement, increment/decrement of the
Syntax syntax break;
counter is done
while(condition)
{ Example
Step 4: After performing this, the test
/*block of statement*/ for(i=0;i<10;i++)
condition is again evaluated. The steps 2
} {
and 3 are repeated till the test condition
/*block of statement*/
returns false
Here, block of statement will be repeated if(i==5)
until condition evaluates to false break;
}
C Programming Course (86% Off)
www.aptuts.com
Example 1
Here, arr[0] = 10, arr[1] = 20 and arr[2] = 30 struct animal int main()
{ {
Example of 2-D array int age; int a = 10;
FILE *fp;
The above statement declares an array fclose(fp);
fp = fopen("file.c","r");
named “name” (or string named "name)
capable of holding 20 characters. The above statement will close the file
The above statement would open file
named “file.c” in “read” mode. It
Example 2
tells the computer that the file being
char name[]=”This is a string”;
opened would be used for reading
purpose only.
Here the size of an array is calculated
automatically
WHY APTUTS?
Take the online courses with the
best personalized support
Learn by doing. Our courses are
hands-on centric
ABOUT FEEL FREE TO PRINT We help you grow professionally
100% money back guarantee
Aptuts was founded by a software AND SHARE THIS
engineer with 11+ years of experience in
IT industry. CHEATSHEET ON C
Our online courses are built in
PROGRAMMING
partnership with technology experts and
are relevant to the current education C Programming Course (86% Off)
and industry needs.
www.aptuts.com
www.fb.com/Aptuts
Programming by Aptuts