Professional Documents
Culture Documents
ELE118 ELE118 C Reference Sheet
ELE118 ELE118 C Reference Sheet
Getting Started:
Conditions (continued):
Complete C Program:
Compound Conditions:
comment
/* A Complete C Program */
A
false
false
true
true
directive
#include <stdio.h>
function
main()
{
printf("\nC you later\n");
}
int
float
char
1, 0, 7, -15
1.0, -12.56, 3.14
'A', 'a', '\n', '7'
switch (cResponse)
{
case 'a':
case 'A':
printf("You selected a or A\n");
break;
case 'b':
case 'B':
printf("You selected b or B\n");
break;
case 'c':
case 'C':
printf("You selected c or C\n");
break;
}
Conversion
Specifier
%d
%f
%c
Loops:
Keyboard Input:
printf("Enter a number: ");
scanf("%f", &myGuess);
condition
A&&B
false
false
false
true
must be an
integral type
switch Structures:
A||B
false
true
true
true
statement
Data Types
B
false
true
false
true
++, -*, /, %
+, >, >=, <, <=
==, !=
&&
||
=, +=, -=, *=, /=, %=
executed when
condition is
true
Conditions:
if Structures:
do
{
condition
executed at
least once
executed when
all conditions are
false (optional)
December 9, 2009
Functions:
Strings:
return
type
void printBalance(int);
pass by reference
Input / Output:
allows entry of a string
scanf("%s", fname);
that contains spaces
gets(lname);
printf("Hi %s %s \n", fname, lname);
Arrays:
Declaration and initialization:
s1)
s1)
s1)
c)
s1)
isalnum(c)
isalpha(c)
isdigit(c)
isspace(c)
tolower(c)
toupper(c)
indexes 0 through 99
int dollars[100];
float values[15] = {1.1, 2.2, 3.1, -1};
Accessing individual elements:
Data Structures:
Declaring a struct:
dollars[3] = 17;
typedef struct {
int x;
int y;
} point;
Pointers:
point first;
first.x = 1;
first.y = 4;
printf("(%d, %d) \n", first.x, first.y);
address of operator
Opening a file:
r for read
w for write
a for append