Professional Documents
Culture Documents
Software Technology Programming: Formatting and Variables Variables
Software Technology Programming: Formatting and Variables Variables
Description
Use
char
letter
int
normal whole
number
number
nothing (executing
code)
Same as int.
Decimal number
float
double
void
Unsigned int
boolean
true or false
Here is a reference list of all the various codes for printing different variable types:
code for
use in
printf
variable
type
format
int
int
x or X
int
ld
long
decimal number ('l' can also be applied to any of the above to change
the type from 'int' to 'long')
unsigned
decimal number
lu
unsigned
long
decimal number
char
single character
char pointer
string
float
float
float
lf
double
lg
double
le
double
White space:
All C compilers ignore any white space (anything that does not have text) this includes blank
lines (enter key) spaces, and tabs. However, that does not mean that one should not format code
properly, or that there is not a correct way to go about that formatting.
Correctly formatted code will look much more like this, it is less dense and far easier to read and
understand. One can read this section of code, and even without and comments, it is possible to
gain some understanding of what this is meant to accomplish. Comments would make this even
better, but good formatting is even more important.
Rules (or Grammar) of Code
; The semicolon is like a period in English, and notates that you are at the end
of a statement or command.
One should press enter after every ; so that only one statement or
command is performed per line of code. Also a blank line should be placed between
sections (paragraphs) or code.
or tab is used to visually display the levels of organization of code. This
sounds complicated, but it is really easy when you start doing it. Basically, each tab stop
is the next level of a function or loop.
Comments:
Comments are a crucial component to all code, for while computers understand code
exceptionally, people can process English must more efficiently. A comment is a separate section
of a program that the computer will ignore upon compilation.
Comments can be defined in two ways:
// Anything after double forward slashes will be ignored by the
compiler (computer).
Example:
#include <stdio.h>
main(){
printf("hello world\n");
} // This function will print the phrase "hello world" on the screen
/*______ */ where anything between the stars will be ignored
Example:
#include <stdio.h>
main(){
printf("hello world\n");
}/*This function will print the phrase "hello world" on the screen*/
Note: All comments will appear in green text.