Date post: | 11-Apr-2017 |
Category: |
Education |
Upload: | thirumalaikumar3 |
View: | 152 times |
Download: | 1 times |
C - Basics
05/03/2023 2
Overview
Introduction Evolution Characteristics Structure of program Input/output statements Command line arguments Escape sequences
Session-1/Dr.M.karthika
Founder of C
Language
Dennis M. Ritchie
05/03/2023Session-1/Dr.M.karthika 4
Introduction
C language is one of the most popular computer language
structured , low level , machine dependent language
05/03/2023Session-1/Dr.M.karthika 5
History of c language C programming language was
developed in 1972 by Dennis Ritchie at bell laboratories of AT&T(American Telephone & Telegraph), located in U.S.A.
It was developed to be used in UNIX Operating system.
It inherits many features of previous languages such as B and BPCL.
EvolutionLanguage year Developed ByALGOL 1960 International GroupBPCL 1967 Martin RichardsB 1970 Ken ThompsonTraditional C 1972 Dennis RitchieK & R C 1978 Kernighan & Dennis
RitchieANSI C 1989 ANSI CommitteeANSI/ISO C 1990 ISO CommitteeC99 1999 Standardization
Committee
What is c language?
C is mother language of all programming language.
It is system programming language. It is procedure-oriented programming
language. It is also called mid level programming
language.
Features of C Language
There are many features of c language are given below.1) Simple2) Machine Independent or Portable3) Mid-level programming language4) structured programming language5) Rich Library6) Memory Management7) Fast Speed8) Pointers9) Recursion10) Extensible
Program structure
A sample C Program
#include<stdio.h>int main(){
--other statements // Comments after double slash}
Wednesday, May 3, 2023 9
Running a C Program
Type a program Save it Compile the program – This will generate
an exe file (executable) Run the program (Actually the exe
created out of compilation will run and not the .c file)
In different compiler we have different option for compiling and running. We give only the concepts.
Wednesday, May 3, 2023 10
Describe the C Program #include <stdio.h> includes the standard input
output library functions. The printf() function is defined in stdio.h .
#include <conio.h> includes the console input output library functions. The getch() function is defined in conio.h file.
void main() The main() function is the entry point of every program in c language. The void keyword specifies that it returns no value.
printf() The printf() function is used to print data on the console.
getch() The getch() function asks for a single character. Until you press any key, it blocks the screen.
The files that are specified in the include section is called as header file
These are precompiled files that has some functions defined in them
We can call those functions in our program by supplying parameters
Header file is given an extension .h C Source file is given an extension .c
Header files
This is the entry point of a program When a file is executed, the start point is
the main function From main function the flow goes as per
the programmers choice. There may or may not be other functions
written by user in a program Main function is compulsory for any C
program
Main function
Describe the C Program:-
#include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h .
#include <conio.h> includes the console input output library functions. The getch() function is defined in conio.h file.
void main() The main() function is the entry point of every program in c language. The void keyword specifies that it returns no value.
printf() The printf() function is used to print data on the console.
getch() The getch() function asks for a single character. Until you press any key, it blocks the screen.
First Program of C Language
#include <stdio.h> #include <conio.h> void main(){ printf("Hello C Language"); getch(); }
Output of Program is,
Hello C Language
Input output function
There are two input output function of c language.
1) First is printf()2) Second is scanf()
05/03/2023Session-1/Dr.M.karthika 18
printf()
printf() function is used for output. It prints the given statement to the console.
Syntax of printf() is given below:printf(“format string”,arguments_list);
Format string can be %d (integer), %c (character), %s (string), %f (float) etc.
scanf()
scanf() Function: is used for input. It reads the input data from console.
scanf(“format string”,argument_list);
Input and Output
Input› scanf(“%d”,&a);› Gets an integer value from the user and
stores it under the name “a” Output
› printf(“%d”,a);› Prints the value present in variable a on
the screen
Wednesday, May 3, 2023 20
Comments in C
Single line comment› // (double slash)› Termination of comment is by pressing
enter key Multi line comment
/*…. …….*/This can span over to multiple lines
Wednesday, May 3, 2023 21
05/03/2023Session-1/Dr.M.karthika 22
Constant Meaning‘a’ Audible Alert (Bell)‘b’ Back Space‘f’ Form Feed‘n’ New Line‘r’ Carriage Return‘t’ Horizontal Tab‘v’ Vertical Tab”’ Single Quote‘”‘ Double Quote‘?’ Question Mark‘\’ Backslash
‘\0’ Null
Escape Sequences
05/03/2023Session-1/Dr.M.karthika 23
Escape Sequences-example /* Testing the escape sequences */#include <stdio.h> int main(void){printf("Testing the escape sequences:\n");printf("-----------------------------\n"); /* 3 times audible tone */printf("The audible bell ---> \\a \a\a\a\n");printf("The backspace ---> \\b___ \bTesting\n"); /* printer must be attached...*/printf("The formfeed, printer ---> \\f \fTest\n");printf("The newline ---> \\n \n\n");printf("The carriage return ---> \\r \rTesting\r\n");printf("The horizontal tab ---> \\t \tTesting\t\n");printf("The vertical tab ---> \\v Testing\v\n");printf("The backslash ---> \\ \\Testing\\\n");printf("The single quote ---> \' \'Testing\'\'\'\n");printf("The double quote ---> \" \"Testing\"\"\n");printf("Some might not work isn't it?\n"); return 0;}
Output example: Testing the escape
sequences:-----------------------------The audible bell ---> \aThe backspace ---> \
b___TestingThe formfeed, printer ---> \f
?TestThe newline ---> \nTestingriage return ---> \rThe horizontal tab ---> \t
TestingThe vertical tab ---> \v
Testing?The backslash ---> \ \
Testing\The single quote ---> '
'Testing' ' 'The double quote ---> "
"Testing""Some might not work isn't
it?Press any key to
continue . . .
05/03/2023Session-1/Dr.M.karthika 24
THANK YOU
05/03/2023Session-1/Dr.M.karthika 25