0% found this document useful (0 votes)
63 views

American International University-Bangladesh (AIUB) : Sarwar Morshed

This document summarizes a lecture on writing basic C programs. It introduces variables, constants, arithmetic, control flow, functions, and input/output. It presents a "Hello World" program as the first example. It discusses functions, variables, libraries, strings, comments, compilation, and asks students to try variations on "Hello World" as a task.

Uploaded by

Tazbir Antu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

American International University-Bangladesh (AIUB) : Sarwar Morshed

This document summarizes a lecture on writing basic C programs. It introduces variables, constants, arithmetic, control flow, functions, and input/output. It presents a "Hello World" program as the first example. It discusses functions, variables, libraries, strings, comments, compilation, and asks students to try variations on "Hello World" as a task.

Uploaded by

Tazbir Antu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

Lecture 1

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

 Rudiments of Input and Output

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”);
}

Compile this program.


Run the executable.
It should print “Hello World”.

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>

*/ print Hello World


in screen /*
void main()
{
// This is a single line comment
printf(“Hello World\n”);
}

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.

Object Code: Translation of the source code of


a program into machine code.

Linker: A program that links separately


compiled functions together into one program.

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.

Compile Time: The events that occur while


your program is being compiled (Syntax Error).

Run Time: The events that occur while your


program is executing.
Sarwar Morshed 11
Task!!!
 Compile and Run hello world program at home. Leave
out parts and see what happens.
 Try to write hello world program using three printf
statements.

Sarwar Morshed 12

You might also like