Learnings of the Week - October 4, 2008
STRUCTURE OF A SIMPLE C PROGRAM
#include
#define directive
main()
{
variable declaration section;
______________________
______________________
}
#include directive – contains information needed by the program to ensure the correct operation of C’s Standard library functions
#define directive – used to shorten the keywords in the program
Variable declaration section – it is the place where you declare your variables
Body of the program – start by typing main() and the { and }. All statements should be written inside the braces.
C is a case sensitive program, therefore use lowercase letters only.
COMMONLY USED INCLUDE FILES IN C LANGUAGE
alloc.h
- declares memory management functions
conio.h
- declares various functions used I calling IBM-PC ROM BIOS
ctype.h
- contains information used by the classification and character convertion macros
math.h
- declares prototype for the math functions
stdio.h
- defines types and macros needed for standard I/O
string.h
- declares several string manipulation and memory manipulation routines
IMPORTANT SYMBOLS
\n
- is a line char used to move the cursor to the next line
‘ ‘
- single quote is used for single character / letter
“ “
- double quote is used for two or more character
{
- open curly brace signifies begin
}
- close curly brace signifies end
&
- address of operator
*
- indirection operator / pointer
INPUT AND OUTPUT STATEMENTS
INPUT STATEMENT
A statement used to input a single character or a sequence of characters from the keyboard.
TYPES OF INPUT STATEMENT
getch
- a function used to input a single character from the keyboard without echoing the character on the monitor.
getche
- a function used to input a single character from the keyboard, the character pressed echoed on the monitor, line the READLN in PASCAL.
getchar
- a function used to input a single character from the keyboard, the character pressed echoed on the monitor terminated by pressing Enter key.
gets
- a function used to input a single character from the keyboard, spaces are accepted, terminated by pressing Enter key.
scanf
- a function used to input a single character or sequence of characters form the keyboard, it needs the control string codes in able to recognized. Spaces are not accepted upon inputting. Terminated by pressing spacebar.
OUTPUT STATEMENT
A statement used to display the argument list or string on the monitor.
TYPES OF OUTPUT STATEMENT
printf
- a function used to display the argument list on the monitor. It sometimes needs the control string codes to help display the remaining argument on the screen.
putchar
- a function used to display the argument list or string on the monitor. It is like overwriting a character
puts
- a function used to display the argument list or string on the monitor. It does not need the help of the control string codes.
FORMAT STRING AND ESCAPE SEQUENCE
All format specifiers start with a percent sign (%) and are followed by a single letter indicating the type of data and how data are to be formatted.
%c
- used for single char in C
scanf(“%c”, &ch);
printf(“%c”, ch);
%d
- decimal number (whole number)
scanf(“%d”,&num);
printf(“%d”,num);
%e
- scientific notation / exponential form
scanf(“%e” &result);
printf(“%e”, result);
%f
- number with floating or decimal point
scanf(“%f”,&pesos); printf(“%f”,pesos);
%o
- octal number
scanf(“%0”, &value);
printf(“%o”, value);
%s
- string of characters
scanf(“%s”,&str);
printf(“%s”,str);
%u
- unsigned number
scanf(“%u”, &value);
printf(“%u”, value);
%x
- hexadecimal numbers
scanf(“%x”,&value);
printf(“%x”,value);
%X
- capital number for hexadecimal number
scanf(“%X”, &nos);
printf(“%X”, nos);
%%
- print a percent sign
scanf(“%%”,%value);
printf(“%%”,value);
LIST OF COMMONLY USED ESCAPE SEQUENCE
\\
- prints backslash
\’
- prints single quotes
\”
- prints double quotes
\?
- prints question mark
\n
- newline
GOTOXY
A function gotoxy is used to send the cursor to the specified location.
INSERTING COMMENT
/*y is assigned a numeric literal*/
ASSIGNMENT STATEMENT
It stores a value or a computational result in a variable. They are commonly used to perform most arithmetic operations in program. It can also be used in printf() statement.
A format specifier %.2f can be used to limit the output being displayed into two decimal places only.
Posted by:
RAE ANGELINE S. PALEN


0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home