Lecture 1
Lecture 1
Introduction
C language
• Compact, fast, and powerful
• “Mid-level” Language
• Wide acceptance
• Supports modular programming style
• Useful for all
• Applications
• C is the native language of UNIX
Programming
• Computers are dumb devices that perform only the tasks applied by
the user
Levels of programming languages
Assembly language
Hardware
C language
• (1970s) Pioneered by Dennis Ritchie
• Mid-level language
• (1983) Standardized by The American National Standards Institute
(ANSI)
• (1999) Last major changes adopted
First program
#include <stdio.h>
main()
{
/* My first program */
printf(“Alsalam Alikom \n");
}
• Case sensitive
• End each statement with a semicolon except comments
• Starting point identified by main()
• Braces {} signify the begin and end of the program
Understanding first program
• #include <stdio.h>
• Should be included at the beginning of every program
• Informs the compiler about the input and output statements like printf
• int main (void)
• Informs the compiler that the name of the program is main
• It returns an integer value “int.”
• main is a special name that indicates program execution starts.
• The keyword void that is enclosed in the parentheses specifies that the function
main takes no arguments
• return 0;
• Labels the completion of execution of main ,
• Returns to the system a status value of 0 (You can use any integer here)
• Zero is used by convention to indicate that the program completed successfully
Functions
• Will be discussed later on
Variable
Function
Return
printf options
• printf(“Alsalamo Alikom \n");
• function in the C library that simply prints or displays its argument on screen
• \n means newline. After printing Alsalam Alikom go to a new for extra printing
• All program statements in C must be terminated by a semicolon (;).
%i or %d int
%c char
%f float
%s string
How does the computer work
• What are the possible operations
• 2*2 What is pi?
• 4*A What is the
diameter?
What does the
• How to calculate the area of a circle?
area mean?
• Area=r*r*pi
Which numbers
are numeric and
which numbers
are float?
Declarations
• Declare an integer int x;
• Declare a charachter char x;
• Declare a float number (with decimal places)float x;
• Mulitple declarations are allowed int x,y,z;