Вы находитесь на странице: 1из 9

Programming in C

Lecture 1
Sharmina Zaman
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
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”.
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.
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.
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.
Comments

# include <stdio.h>

/* print Hello World


in screen */
void main()
{
// This is a single line comment
printf(“Hello World\n”);
}
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.
• 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.
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.

Вам также может понравиться