American International University-Bangladesh (AIUB) : Sarwar Morshed
American International University-Bangladesh (AIUB) : Sarwar Morshed
Sarwar Morshed
American International University-Bangladesh (AIUB)
Sarwar Morshed 1
Quick Intro to C
Goal is to get you to a point where you can write useful
programs.
Without getting bogged down into rules, details and
exception (All these will come in later parts)
Concentrate on the basics:
Variables
Constants
Arithmetic
Control-Flow
Functions
Sarwar Morshed 2
Your first C Program
The Hello World Program
Print the words hello, world
# include <stdio.h>
void main()
{
printf(“Hello World\n”);
}
Sarwar Morshed 3
Functions and Variables
A C program what ever its size may be, consists of
functions and variables.
Functions specify computing operations that needs to
be done.
Variables store values during the computation.
What is main function?
“main” is a special function where your program starts
executing.
It is the beginning of your program.
Sarwar Morshed 4
Libraries
# include <stdio.h>
This tells the compiler to add information about
standard library.
After adding this line. You will be able to use functions
and variables declared in stdio.h library.
Sarwar Morshed 5
Libraries
Sarwar Morshed 6
Libraries
Sarwar Morshed 7
Character String or String Constants
“hello world\n”
Enclosed in double quotation marks.
\n is a newline character.
\ is a escape sequence.
So how do we print “ marks?
Escape sequence is used to print hard to type or invisible
characters.
\t is tab, \b is back space, \\ is backslash.
Sarwar Morshed 8
Comments
# include <stdio.h>
Sarwar Morshed 9
Few Definitions
Source Code: The text of a program that a user
can read. The source code is the input to C
compiler.
Sarwar Morshed 10
Few Definitions
Library: The file contains standard functions
that can be used by your program. <stdio.h>
Without it you cannot print anything to the
screen.
Sarwar Morshed 12