C Cheat Sheet Page 2

ADVERTISEMENT

2
All arrays start with their first element as array[0] and last as array[length-1 ]
Commands
printf
printf("literal text to print ");
printf("literal text to print special sequence ");
printf("literal text to print placeholder(s) ",variable(s) );
printf("literal text to print placeholder(s) special sequence ",variable(s) );
Special sequences include n which creates a new line in the terminal. If you have more than one
placeholder list the variables separated by commas var1, var2 and they print in left to right
order.
scanf
scanf("placeholder ",&variable );
Sets value of variable to the input value.
if
if(condition )
commands
Will execute the commands contained within curly braces if the condition is true. Otherwise the
commands are skipped.
Syntax True if value of a is ... the value of b
Equal to.
a==b
Less than or equal to.
a<=b
Greater than or equal to.
a>=b
Less than.
a<b
Greater than.
a>b
Not equal to.
a!=b
do loop
do
commands
while(condition to continue loop);
The do loop executes as long as the condition in the while statement is true.
for loop
for(initial setting ;condition to continue loop ;operate every time round loop )
commands
e.g.
for(i=0;i<10;i++)
printf("%d n",array[i]);
Prints the first ten values in the array (assuming the array is at lest ten elements long as is of
type integer).
i++ is short for i=i+1.
Note i must be an integer because it is used to specify elements in
the array.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2