SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Slide 1 of 53Ver. 1.0
Programming in C
In this session, you will learn to:
Identify the benefits and features of C language
Use the data types available in C language
Identify the structure of C functions
Use input-output functions
Use constructs
Objectives
Slide 2 of 53Ver. 1.0
Programming in C
Identifying the Benefits and Features of C Language
Ken Thompson developed a new language called B.
B language was interpreter-based, hence it was slow.
Dennis Ritchie modified B language and made it a
compiler-based language.
The modified compiler-based B language is named as C.
Slide 3 of 53Ver. 1.0
Programming in C
C language:
Possesses powerful low-level features of second generation
languages.
Provides loops and constructs available in third generation
languages.
Is very powerful and flexible.
C as a Second and Third Generation Language
Slide 4 of 53Ver. 1.0
Programming in C
C language:
Offers all essentials of structured programming.
Has functions that work along with other user-developed
functions and can be used as building blocks for advanced
functions.
Offers only a handful of functions, which form the core of the
language.
Has rest of the functions available in libraries. These functions
are developed using the core functions.
Block Structured Language - An Advantage for Modular
Programming
Slide 5 of 53Ver. 1.0
Programming in C
Features of the C Language
The features that make C a widely-used language are:
Pointers: Allows reference to a memory location by a name.
Memory Allocation: Allows static as well as dynamic memory
allocation.
Recursion: Is a process in which a functions calls itself.
Bit Manipulation: Allows manipulation of data in its lowest form
of storage.
Slide 6 of 53Ver. 1.0
Programming in C
Using the Data Types Available in C language
The types of data structures provided by C can be classified
under the following categories:
Fundamental data types
Derived data types
Slide 7 of 53Ver. 1.0
Programming in C
Fundamental Data Types
Fundamental Data Types:
Are the data types at the lowest level.
Are used for actual data representation in the memory.
Are the base for other data types.
Have machine dependent storage requirement.
Are of the following three types:
char
int
float
Slide 8 of 53Ver. 1.0
Programming in C
The storage requirement for fundamental data types can be
represented with the help of the following table.
Data Number of bytes on a
32-byte machine
Minimum Maximum
char 1 -128 127
int 4 -2^31 (2^31) - 1
float 4 6 digits of precision 6 digits of precision
Fundamental Data Types (Contd.)
Slide 9 of 53Ver. 1.0
Programming in C
Derived Data Types
Derived Data Types:
Are represented in memory as fundamental data type.
Some derived data types are:
short int
long int
double float
Slide 10 of 53Ver. 1.0
Programming in C
The storage requirement for derived data types can be
represented with the help of the following table.
Data Number of bytes
on a 32-byte
machine
Minimum Maximum
short int 2 -2^15 (2^15) - 1
long int 4 -2^31 (2^31) - 1
double float 8 12 digits of precision 6 digits of
precision
Derived Data Types (Contd.)
Slide 11 of 53Ver. 1.0
Programming in C
Defining Data
The syntax for defining data is:
[data type] [variable name],...;
Declaration is done in the beginning of a function.
Definition for various data types is shown in the following
table.
Data definition Data type Memory defined Size (bytes) Value assigned
char a, c; char a
c
1
1
-
-
char a = 'Z'; char a 1 Z
int count; int count 4 -
int a, count =10; int a
count
4
4
-
10
float fnum; float fnum 4 -
float fnum1,
fnum2 = 93.63;
float fnum1
fnum2
4
4
-
93.63
Slide 12 of 53Ver. 1.0
Programming in C
Practice: 1.1
Write the appropriate definitions for defining the following
variables:
1. num to store integers.
2. chr to store a character and assign the character Z to it.
3. num to store a number and assign the value 8.93 to it.
4. i, j to store integers and assign the value 0 to j.
Slide 13 of 53Ver. 1.0
Programming in C
Practice: 1.1 (Contd.)
Solution:
1. int num;
2. char chr=’Z’;
3. float num = 8.93;
4. int i, j=0;
Slide 14 of 53Ver. 1.0
Programming in C
Defining Strings:
Syntax:
char (variable) [(number of bytes)];
Here number of bytes is one more than the number of
characters to store.
To define a memory location of 10 bytes or to store 9 valid
characters, the string will be defined as follows:
char string [10];
Defining Data (Contd.)
Slide 15 of 53Ver. 1.0
Programming in C
Practice: 1.2
Write the appropriate definitions for defining the following
strings:
1. addrs to store 30 characters.
2. head to store 14 characters.
Slide 16 of 53Ver. 1.0
Programming in C
Practice: 1.2 (Contd.)
Solution:
1. char addrs[31];
2. char head[15];
Slide 17 of 53Ver. 1.0
Programming in C
Identifying the Structure of C Functions
In C language, the functions can be categorized in the
following categories:
Single-level functions
Multiple-level functions
Slide 18 of 53Ver. 1.0
Programming in C
Single Level Functions
Single Level Functions:
Consider the following single-level function:
main()
{
/*print a message*/
printf("Welcome to C");
}
In the preceding function:
main(): Is the first function to be executed.
(): Are used for passing parameters to a function.
{}: Are used to mark the beginning and end of a function. These
are mandatory in all functions.
/* */: Is used for documenting various parts of a function.
Slide 19 of 53Ver. 1.0
Programming in C
Semicolon (;): Is used for marking the end of an executable
line.
printf(): Is a C function for printing (displaying) constant or
variable data.
Single Level Functions (Contd.)
Slide 20 of 53Ver. 1.0
Programming in C
Practice: 1.3
Identify any erroneous or missing component(s) in the
following functions:
1. man()
{
printf("This function seems to be okay")
}
2. man()
{
/*print a line*/
printf("This function is perfect“;
}
Slide 21 of 53Ver. 1.0
Programming in C
Practice: 1.3 (Contd.)
3. main()
}
printf("This has got to be right");
{
4. main()
{
This is a perfect comment line
printf("Is it okay?");
}
Slide 22 of 53Ver. 1.0
Programming in C
Solution:
1. man instead of main() and semi-colon missing at the end of
the printf() function.
2. mam instead of main() and ‘)’ missing at the end of the
printf() function.
3. ‘}’ instead of ‘{‘ for marking the beginning of the function and
‘{’ instead of ‘}‘ for marking the end of the function.
4. Comment line should be enclose between /* and */.
Practice: 1.3 (Contd.)
Slide 23 of 53Ver. 1.0
Programming in C
Multiple Level Functions
The following example shows functions at multiple
levels - one being called by another:
main ()
{
/* print a message */
printf ("Welcome to C.");
disp_msg ();
printf ("for good learning");
}
disp_msg ()
{
/* print another message */
printf ("All the best");
}
Slide 24 of 53Ver. 1.0
Programming in C
The output of the preceding program is:
Welcome to C. All the best for good learning.
In the preceding program:
main(): Is the first function to be executed.
disp_msg(): Is a programmer-defined function that can be
independently called by any other function.
(): Are used for passing values to functions, depending on
whether the receiving function is expecting any parameter.
Semicolon (;): Is used to terminate executable lines.
Multiple Level Functions (Contd.)
Slide 25 of 53Ver. 1.0
Programming in C
Practice: 1.4
Identify any erroneous or missing component(s) in the
following functions:
a. print_msg()
{ main();
printf(“bye”);
}
main()
{ printf(“This is the main function”);}
b. main()
{ /*call another function*/
dis_error();
}
disp_err();
{ printf(“Error in function”);}
Slide 26 of 53Ver. 1.0
Programming in C
Solution:
a. main() is always the first function to be executed. Further
execution of the program depends on functions invoked from
main(). Here, after executing printf(), the program
terminates as no other function is invoked. The function
print_msg is not invoked, hence it is not executed.
b. The two functions, dis_error() and disp_error, are not
the same because the function names are different.
Practice: 1.4 (Contd.)
Slide 27 of 53Ver. 1.0
Programming in C
Using the Input-Output Functions
The C environment and the input and output operations are
shown in the following figure.
C Environment
Standard Error Device (stderr)
Standard Input Device (stdin) Standard Output Device (stdout)
Slide 28 of 53Ver. 1.0
Programming in C
Using the Input-Output Functions (Contd.)
These are assumed to be always linked to the C
environment:
stdin - refers to keyboard
stdin - refers to keyboard
stdout - refers to VDU
stderr - refers to VDU
Input and output takes place as a stream of characters.
Each device is linked to a buffer through which the flow of
characters takes place.
After an input operation from the standard input device, care
must be taken to clear input buffer.
Slide 29 of 53Ver. 1.0
Programming in C
Character-Based Input-Output Functions
Character-Based Input-Output Functions are:
getc()
putc()
getchar()
putchar()
The following example uses the getc() and putc()
functions:
# include < stdio.h>
/* function to accept and display a character*/
main ()
{char alph;
alph = getc (stdin); /* accept a character */
fflush (stdin); /* clear the stdin buffer*/
putc (alph, stdout); /* display a character*/
}
Slide 30 of 53Ver. 1.0
Programming in C
The following example uses the getchar() and
putchar() functions:
# include < stdio.h >
/* function to input and display a character using the
function getchar() */
main () {
char c;
c = getchar ();
fflush (stdin); /* clear the buffer */
putchar (c);
}
Character-Based Input-Output Functions (Contd.)
Slide 31 of 53Ver. 1.0
Programming in C
Practice: 1.5
1. Write a function to input a character and display the
character input twice.
Slide 32 of 53Ver. 1.0
Programming in C
Practice: 1.5 (Contd.)
Solution:
Microsoft Word
Document
Slide 33 of 53Ver. 1.0
Programming in C
Practice: 1.6
1. Write a function to accept and store two characters in
different memory locations, and to display them one after
the other using the functions getchar() and
putchar().
Slide 34 of 53Ver. 1.0
Programming in C
Practice: 1.6 (Contd.)
Solution:
/* function to accept and display two characters*/
#include<stdio.h>
main()
{
char a, b;
a=getchar();
fflush(stdin);
b=getchar();
fflush(stdin);
putchar(a);
putchar(b);
}
Slide 35 of 53Ver. 1.0
Programming in C
String-Based Input-Output Functions
String-based input-output functions are:
gets()
puts()
The following example uses the gets() and puts()
functions:
# include < stdio.h >
/* function to accept and displaying */
main ()
{ char in_str {21}; /* display prompt */
puts ("Enter a String of max 20 characters");
gets (in_str); /* accept string */
fflush (stdin); /* clear the buffer */
puts (in_str); /* display input string */
}
Slide 36 of 53Ver. 1.0
Programming in C
Practice: 1.7
1. Write a function that prompts for and accepts a name with a
maximum of 25 characters, and displays the following
message.
Hello. How are you?
(name)
2. Write a function that prompts for a name (up to 20
characters) and address (up to 30 characters) and accepts
them one at a time. Finally, the name and address are
displayed in the following way.
Your name is:
(name)
Your address is:
(address)
Slide 37 of 53Ver. 1.0
Programming in C
Solution:
Practice: 1.7 (Contd.)
Microsoft Word
Document
Slide 38 of 53Ver. 1.0
Programming in C
Using Constructs
There are two types of constructs in C language:
Conditional constructs
Loop constructs
Slide 39 of 53Ver. 1.0
Programming in C
Conditional Constructs
Conditional Constructs:
Requires relation operators as in other programming language
with a slight change in symbols used for relational operators.
The two types of conditional constructs in C are:
if..else construct
switch…case construct
Slide 40 of 53Ver. 1.0
Programming in C
The Syntax of the if..else construct is as follows:
if (condition)
{
statement 1 ;
statement 2 ;
:
}
else
{
statement 1 ;
statement 2 ;
:
}
Conditional Constructs (Contd.)
Slide 41 of 53Ver. 1.0
Programming in C
Practice: 1.8
1. Write a function that accepts one-character grade code, and
depending on what grade is input, display the HRA
percentage according to the following table.
Grade HRA %
A 45%
B 40%
C 30%
D 25%
Slide 42 of 53Ver. 1.0
Programming in C
Practice: 1.8 (Contd.)
Identify errors, if any, in the following function:
#include<stdio.h>
/*function to check if y or n is input*/
main()
{
char yn;
puts("Enter y or n for yes/no");
yn = getchar();
fflush(stdin);
if(yn=’y’)
puts("You entered y");
else if(yn=‘n')
puts("You entered n");
else
puts("Invalid input");
}
Slide 43 of 53Ver. 1.0
Programming in C
Solution:
Practice: 1.8 (Contd.)
Microsoft Word
Document
Slide 44 of 53Ver. 1.0
Programming in C
Syntax of switch…case construct:
switch (variable)
{
case 1 :
statement1 ;
break ;
case 2 :
statement 2 ;
:
:
break;
default :
statement
}
Conditional Constructs (Contd.)
Slide 45 of 53Ver. 1.0
Programming in C
Practice: 1.9
Write a function to display the following menu and accept a
choice number. If an invalid choice is entered then an
appropriate error message must be displayed, else the
choice number entered must be displayed.
Menu
1. Create a directory
2. Delete a directory
3. Show a directory
4. Exit
Your choice:
Slide 46 of 53Ver. 1.0
Programming in C
Solution:
Practice: 1.9 (Contd.)
Microsoft Word
Document
Slide 47 of 53Ver. 1.0
Programming in C
Loop Constructs
The two types of conditional constructs in C are:
while loop construct.
do..while construct.
The while loop construct has the following syntax:
while (condition in true)
{
statement 1 ; loop
statement 2 ; body
}
Used to iterate a set of instructions (the loop body) as long as
the specified condition is true.
Slide 48 of 53Ver. 1.0
Programming in C
The do..while loop construct:
The do..while loop is similar to the while loop, except that the
condition is checked after execution of the body.
The do..while loop is executed at least once.
The following figure shows the difference between the while loop
and the do...while loop.
Loop Constructs (Contd.)
while
Evaluate
Condition
Execute
Body of
Loop
True
False
do while
Evaluate
Condition
Execute
Body of
Loop
True
False
Slide 49 of 53Ver. 1.0
Programming in C
Practice: 1.10
1. Write a function to accept characters from the keyboard
until the character ‘!’ is input, and to display whether the
total number of non-vowel characters entered is more than,
less than, or equal to the total number of vowels entered.
Slide 50 of 53Ver. 1.0
Programming in C
Practice: 1.10 (Contd.)
Solution:
Microsoft Word
Document
Slide 51 of 53Ver. 1.0
Programming in C
Summary
In this session, you learned that:
C language was developed by Ken Thompson and Dennis
Ritchie.
C language combines the features of second and third
generation languages.
C language is a block structured language.
C language has various features that make it a widely-used
language. Some of the important features are:
Pointers
Memory Allocation
Recursion
Bit-manipulation
Slide 52 of 53Ver. 1.0
Programming in C
Summary (Contd.)
The types of data structures provided by C can be classified
under the following categories:
Fundamental data types: Include the data types, which are used
for actual data representation in the memory.
Derived data types: Are based on fundamental data types.
Fundamental data types:
char, int, and float
Some of the derived data types are:
short int, long int, and double float
Definition of memory for any data, both fundamental and
derived data types, is done in the following format:
[data type] [variable name],...;
Slide 53 of 53Ver. 1.0
Programming in C
Summary (Contd.)
In C language, the functions can be categorized in the
following categories:
Single-level functions
Multiple-level functions
For standard input-output operations, the C environment uses
stdin, stdout, and stderr as references for accessing the
devices.
There are two types of constructs in C language:
Conditional constructs
Loop constructs

Weitere ähnliche Inhalte

Was ist angesagt?

C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
Storage classes, linkage & memory management
Storage classes, linkage & memory managementStorage classes, linkage & memory management
Storage classes, linkage & memory managementMomenMostafa
 
C programming session 02
C programming session 02C programming session 02
C programming session 02Vivek Singh
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programminggajendra singh
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c languageRavindraSalunke3
 
Advanced C Language for Engineering
Advanced C Language for EngineeringAdvanced C Language for Engineering
Advanced C Language for EngineeringVincenzo De Florio
 
User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.NabeelaNousheen
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manualAnil Bishnoi
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)Ashishchinu
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notesSrikanth
 

Was ist angesagt? (18)

C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Structures-2
Structures-2Structures-2
Structures-2
 
Storage classes, linkage & memory management
Storage classes, linkage & memory managementStorage classes, linkage & memory management
Storage classes, linkage & memory management
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
C programming session 02
C programming session 02C programming session 02
C programming session 02
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Computer Programming - Lecture 2
Computer Programming - Lecture 2Computer Programming - Lecture 2
Computer Programming - Lecture 2
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c language
 
Advanced C Language for Engineering
Advanced C Language for EngineeringAdvanced C Language for Engineering
Advanced C Language for Engineering
 
C programming
C programmingC programming
C programming
 
User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.User_Defined_Functions_ppt_slideshare.
User_Defined_Functions_ppt_slideshare.
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
C notes
C notesC notes
C notes
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
 

Ähnlich wie C programming session 01

C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introductionraghukatagall2
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1SURBHI SAROHA
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYRajeshkumar Reddy
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docxeugeniadean34240
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptxVishwas459764
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Rohit Singh
 
A Crash Course in C Part-1
A Crash Course in C Part-1A Crash Course in C Part-1
A Crash Course in C Part-1MD SAMIR UDDIN
 
Introduction to c
Introduction to cIntroduction to c
Introduction to camol_chavan
 

Ähnlich wie C programming session 01 (20)

C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introduction
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
2.Overview of C language.pptx
2.Overview of C language.pptx2.Overview of C language.pptx
2.Overview of C language.pptx
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
c.ppt
c.pptc.ppt
c.ppt
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Basic c
Basic cBasic c
Basic c
 
C programming day#1
C programming day#1C programming day#1
C programming day#1
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)
 
A Crash Course in C Part-1
A Crash Course in C Part-1A Crash Course in C Part-1
A Crash Course in C Part-1
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 

Mehr von Vivek Singh

C programming session 14
C programming session 14C programming session 14
C programming session 14Vivek Singh
 
C programming session 13
C programming session 13C programming session 13
C programming session 13Vivek Singh
 
C programming session 11
C programming session 11C programming session 11
C programming session 11Vivek Singh
 
C programming session 10
C programming session 10C programming session 10
C programming session 10Vivek Singh
 
C programming session 08
C programming session 08C programming session 08
C programming session 08Vivek Singh
 
C programming session 07
C programming session 07C programming session 07
C programming session 07Vivek Singh
 
C programming session 05
C programming session 05C programming session 05
C programming session 05Vivek Singh
 
C programming session 04
C programming session 04C programming session 04
C programming session 04Vivek Singh
 
C programming session 16
C programming session 16C programming session 16
C programming session 16Vivek Singh
 
Niit aptitude question paper
Niit aptitude question paperNiit aptitude question paper
Niit aptitude question paperVivek Singh
 
Excel shortcut and tips
Excel shortcut and tipsExcel shortcut and tips
Excel shortcut and tipsVivek Singh
 
Sql where clause
Sql where clauseSql where clause
Sql where clauseVivek Singh
 
Sql update statement
Sql update statementSql update statement
Sql update statementVivek Singh
 
Sql tutorial, tutorials sql
Sql tutorial, tutorials sqlSql tutorial, tutorials sql
Sql tutorial, tutorials sqlVivek Singh
 
Sql select statement
Sql select statementSql select statement
Sql select statementVivek Singh
 
Sql query tuning or query optimization
Sql query tuning or query optimizationSql query tuning or query optimization
Sql query tuning or query optimizationVivek Singh
 
Sql query tips or query optimization
Sql query tips or query optimizationSql query tips or query optimization
Sql query tips or query optimizationVivek Singh
 
Sql order by clause
Sql order by clauseSql order by clause
Sql order by clauseVivek Singh
 

Mehr von Vivek Singh (20)

C programming session 14
C programming session 14C programming session 14
C programming session 14
 
C programming session 13
C programming session 13C programming session 13
C programming session 13
 
C programming session 11
C programming session 11C programming session 11
C programming session 11
 
C programming session 10
C programming session 10C programming session 10
C programming session 10
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
 
C programming session 07
C programming session 07C programming session 07
C programming session 07
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
C programming session 16
C programming session 16C programming session 16
C programming session 16
 
Niit aptitude question paper
Niit aptitude question paperNiit aptitude question paper
Niit aptitude question paper
 
Excel shortcut and tips
Excel shortcut and tipsExcel shortcut and tips
Excel shortcut and tips
 
Sql where clause
Sql where clauseSql where clause
Sql where clause
 
Sql update statement
Sql update statementSql update statement
Sql update statement
 
Sql tutorial, tutorials sql
Sql tutorial, tutorials sqlSql tutorial, tutorials sql
Sql tutorial, tutorials sql
 
Sql subquery
Sql subquerySql subquery
Sql subquery
 
Sql select statement
Sql select statementSql select statement
Sql select statement
 
Sql rename
Sql renameSql rename
Sql rename
 
Sql query tuning or query optimization
Sql query tuning or query optimizationSql query tuning or query optimization
Sql query tuning or query optimization
 
Sql query tips or query optimization
Sql query tips or query optimizationSql query tips or query optimization
Sql query tips or query optimization
 
Sql order by clause
Sql order by clauseSql order by clause
Sql order by clause
 

Kürzlich hochgeladen

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 

Kürzlich hochgeladen (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

C programming session 01

  • 1. Slide 1 of 53Ver. 1.0 Programming in C In this session, you will learn to: Identify the benefits and features of C language Use the data types available in C language Identify the structure of C functions Use input-output functions Use constructs Objectives
  • 2. Slide 2 of 53Ver. 1.0 Programming in C Identifying the Benefits and Features of C Language Ken Thompson developed a new language called B. B language was interpreter-based, hence it was slow. Dennis Ritchie modified B language and made it a compiler-based language. The modified compiler-based B language is named as C.
  • 3. Slide 3 of 53Ver. 1.0 Programming in C C language: Possesses powerful low-level features of second generation languages. Provides loops and constructs available in third generation languages. Is very powerful and flexible. C as a Second and Third Generation Language
  • 4. Slide 4 of 53Ver. 1.0 Programming in C C language: Offers all essentials of structured programming. Has functions that work along with other user-developed functions and can be used as building blocks for advanced functions. Offers only a handful of functions, which form the core of the language. Has rest of the functions available in libraries. These functions are developed using the core functions. Block Structured Language - An Advantage for Modular Programming
  • 5. Slide 5 of 53Ver. 1.0 Programming in C Features of the C Language The features that make C a widely-used language are: Pointers: Allows reference to a memory location by a name. Memory Allocation: Allows static as well as dynamic memory allocation. Recursion: Is a process in which a functions calls itself. Bit Manipulation: Allows manipulation of data in its lowest form of storage.
  • 6. Slide 6 of 53Ver. 1.0 Programming in C Using the Data Types Available in C language The types of data structures provided by C can be classified under the following categories: Fundamental data types Derived data types
  • 7. Slide 7 of 53Ver. 1.0 Programming in C Fundamental Data Types Fundamental Data Types: Are the data types at the lowest level. Are used for actual data representation in the memory. Are the base for other data types. Have machine dependent storage requirement. Are of the following three types: char int float
  • 8. Slide 8 of 53Ver. 1.0 Programming in C The storage requirement for fundamental data types can be represented with the help of the following table. Data Number of bytes on a 32-byte machine Minimum Maximum char 1 -128 127 int 4 -2^31 (2^31) - 1 float 4 6 digits of precision 6 digits of precision Fundamental Data Types (Contd.)
  • 9. Slide 9 of 53Ver. 1.0 Programming in C Derived Data Types Derived Data Types: Are represented in memory as fundamental data type. Some derived data types are: short int long int double float
  • 10. Slide 10 of 53Ver. 1.0 Programming in C The storage requirement for derived data types can be represented with the help of the following table. Data Number of bytes on a 32-byte machine Minimum Maximum short int 2 -2^15 (2^15) - 1 long int 4 -2^31 (2^31) - 1 double float 8 12 digits of precision 6 digits of precision Derived Data Types (Contd.)
  • 11. Slide 11 of 53Ver. 1.0 Programming in C Defining Data The syntax for defining data is: [data type] [variable name],...; Declaration is done in the beginning of a function. Definition for various data types is shown in the following table. Data definition Data type Memory defined Size (bytes) Value assigned char a, c; char a c 1 1 - - char a = 'Z'; char a 1 Z int count; int count 4 - int a, count =10; int a count 4 4 - 10 float fnum; float fnum 4 - float fnum1, fnum2 = 93.63; float fnum1 fnum2 4 4 - 93.63
  • 12. Slide 12 of 53Ver. 1.0 Programming in C Practice: 1.1 Write the appropriate definitions for defining the following variables: 1. num to store integers. 2. chr to store a character and assign the character Z to it. 3. num to store a number and assign the value 8.93 to it. 4. i, j to store integers and assign the value 0 to j.
  • 13. Slide 13 of 53Ver. 1.0 Programming in C Practice: 1.1 (Contd.) Solution: 1. int num; 2. char chr=’Z’; 3. float num = 8.93; 4. int i, j=0;
  • 14. Slide 14 of 53Ver. 1.0 Programming in C Defining Strings: Syntax: char (variable) [(number of bytes)]; Here number of bytes is one more than the number of characters to store. To define a memory location of 10 bytes or to store 9 valid characters, the string will be defined as follows: char string [10]; Defining Data (Contd.)
  • 15. Slide 15 of 53Ver. 1.0 Programming in C Practice: 1.2 Write the appropriate definitions for defining the following strings: 1. addrs to store 30 characters. 2. head to store 14 characters.
  • 16. Slide 16 of 53Ver. 1.0 Programming in C Practice: 1.2 (Contd.) Solution: 1. char addrs[31]; 2. char head[15];
  • 17. Slide 17 of 53Ver. 1.0 Programming in C Identifying the Structure of C Functions In C language, the functions can be categorized in the following categories: Single-level functions Multiple-level functions
  • 18. Slide 18 of 53Ver. 1.0 Programming in C Single Level Functions Single Level Functions: Consider the following single-level function: main() { /*print a message*/ printf("Welcome to C"); } In the preceding function: main(): Is the first function to be executed. (): Are used for passing parameters to a function. {}: Are used to mark the beginning and end of a function. These are mandatory in all functions. /* */: Is used for documenting various parts of a function.
  • 19. Slide 19 of 53Ver. 1.0 Programming in C Semicolon (;): Is used for marking the end of an executable line. printf(): Is a C function for printing (displaying) constant or variable data. Single Level Functions (Contd.)
  • 20. Slide 20 of 53Ver. 1.0 Programming in C Practice: 1.3 Identify any erroneous or missing component(s) in the following functions: 1. man() { printf("This function seems to be okay") } 2. man() { /*print a line*/ printf("This function is perfect“; }
  • 21. Slide 21 of 53Ver. 1.0 Programming in C Practice: 1.3 (Contd.) 3. main() } printf("This has got to be right"); { 4. main() { This is a perfect comment line printf("Is it okay?"); }
  • 22. Slide 22 of 53Ver. 1.0 Programming in C Solution: 1. man instead of main() and semi-colon missing at the end of the printf() function. 2. mam instead of main() and ‘)’ missing at the end of the printf() function. 3. ‘}’ instead of ‘{‘ for marking the beginning of the function and ‘{’ instead of ‘}‘ for marking the end of the function. 4. Comment line should be enclose between /* and */. Practice: 1.3 (Contd.)
  • 23. Slide 23 of 53Ver. 1.0 Programming in C Multiple Level Functions The following example shows functions at multiple levels - one being called by another: main () { /* print a message */ printf ("Welcome to C."); disp_msg (); printf ("for good learning"); } disp_msg () { /* print another message */ printf ("All the best"); }
  • 24. Slide 24 of 53Ver. 1.0 Programming in C The output of the preceding program is: Welcome to C. All the best for good learning. In the preceding program: main(): Is the first function to be executed. disp_msg(): Is a programmer-defined function that can be independently called by any other function. (): Are used for passing values to functions, depending on whether the receiving function is expecting any parameter. Semicolon (;): Is used to terminate executable lines. Multiple Level Functions (Contd.)
  • 25. Slide 25 of 53Ver. 1.0 Programming in C Practice: 1.4 Identify any erroneous or missing component(s) in the following functions: a. print_msg() { main(); printf(“bye”); } main() { printf(“This is the main function”);} b. main() { /*call another function*/ dis_error(); } disp_err(); { printf(“Error in function”);}
  • 26. Slide 26 of 53Ver. 1.0 Programming in C Solution: a. main() is always the first function to be executed. Further execution of the program depends on functions invoked from main(). Here, after executing printf(), the program terminates as no other function is invoked. The function print_msg is not invoked, hence it is not executed. b. The two functions, dis_error() and disp_error, are not the same because the function names are different. Practice: 1.4 (Contd.)
  • 27. Slide 27 of 53Ver. 1.0 Programming in C Using the Input-Output Functions The C environment and the input and output operations are shown in the following figure. C Environment Standard Error Device (stderr) Standard Input Device (stdin) Standard Output Device (stdout)
  • 28. Slide 28 of 53Ver. 1.0 Programming in C Using the Input-Output Functions (Contd.) These are assumed to be always linked to the C environment: stdin - refers to keyboard stdin - refers to keyboard stdout - refers to VDU stderr - refers to VDU Input and output takes place as a stream of characters. Each device is linked to a buffer through which the flow of characters takes place. After an input operation from the standard input device, care must be taken to clear input buffer.
  • 29. Slide 29 of 53Ver. 1.0 Programming in C Character-Based Input-Output Functions Character-Based Input-Output Functions are: getc() putc() getchar() putchar() The following example uses the getc() and putc() functions: # include < stdio.h> /* function to accept and display a character*/ main () {char alph; alph = getc (stdin); /* accept a character */ fflush (stdin); /* clear the stdin buffer*/ putc (alph, stdout); /* display a character*/ }
  • 30. Slide 30 of 53Ver. 1.0 Programming in C The following example uses the getchar() and putchar() functions: # include < stdio.h > /* function to input and display a character using the function getchar() */ main () { char c; c = getchar (); fflush (stdin); /* clear the buffer */ putchar (c); } Character-Based Input-Output Functions (Contd.)
  • 31. Slide 31 of 53Ver. 1.0 Programming in C Practice: 1.5 1. Write a function to input a character and display the character input twice.
  • 32. Slide 32 of 53Ver. 1.0 Programming in C Practice: 1.5 (Contd.) Solution: Microsoft Word Document
  • 33. Slide 33 of 53Ver. 1.0 Programming in C Practice: 1.6 1. Write a function to accept and store two characters in different memory locations, and to display them one after the other using the functions getchar() and putchar().
  • 34. Slide 34 of 53Ver. 1.0 Programming in C Practice: 1.6 (Contd.) Solution: /* function to accept and display two characters*/ #include<stdio.h> main() { char a, b; a=getchar(); fflush(stdin); b=getchar(); fflush(stdin); putchar(a); putchar(b); }
  • 35. Slide 35 of 53Ver. 1.0 Programming in C String-Based Input-Output Functions String-based input-output functions are: gets() puts() The following example uses the gets() and puts() functions: # include < stdio.h > /* function to accept and displaying */ main () { char in_str {21}; /* display prompt */ puts ("Enter a String of max 20 characters"); gets (in_str); /* accept string */ fflush (stdin); /* clear the buffer */ puts (in_str); /* display input string */ }
  • 36. Slide 36 of 53Ver. 1.0 Programming in C Practice: 1.7 1. Write a function that prompts for and accepts a name with a maximum of 25 characters, and displays the following message. Hello. How are you? (name) 2. Write a function that prompts for a name (up to 20 characters) and address (up to 30 characters) and accepts them one at a time. Finally, the name and address are displayed in the following way. Your name is: (name) Your address is: (address)
  • 37. Slide 37 of 53Ver. 1.0 Programming in C Solution: Practice: 1.7 (Contd.) Microsoft Word Document
  • 38. Slide 38 of 53Ver. 1.0 Programming in C Using Constructs There are two types of constructs in C language: Conditional constructs Loop constructs
  • 39. Slide 39 of 53Ver. 1.0 Programming in C Conditional Constructs Conditional Constructs: Requires relation operators as in other programming language with a slight change in symbols used for relational operators. The two types of conditional constructs in C are: if..else construct switch…case construct
  • 40. Slide 40 of 53Ver. 1.0 Programming in C The Syntax of the if..else construct is as follows: if (condition) { statement 1 ; statement 2 ; : } else { statement 1 ; statement 2 ; : } Conditional Constructs (Contd.)
  • 41. Slide 41 of 53Ver. 1.0 Programming in C Practice: 1.8 1. Write a function that accepts one-character grade code, and depending on what grade is input, display the HRA percentage according to the following table. Grade HRA % A 45% B 40% C 30% D 25%
  • 42. Slide 42 of 53Ver. 1.0 Programming in C Practice: 1.8 (Contd.) Identify errors, if any, in the following function: #include<stdio.h> /*function to check if y or n is input*/ main() { char yn; puts("Enter y or n for yes/no"); yn = getchar(); fflush(stdin); if(yn=’y’) puts("You entered y"); else if(yn=‘n') puts("You entered n"); else puts("Invalid input"); }
  • 43. Slide 43 of 53Ver. 1.0 Programming in C Solution: Practice: 1.8 (Contd.) Microsoft Word Document
  • 44. Slide 44 of 53Ver. 1.0 Programming in C Syntax of switch…case construct: switch (variable) { case 1 : statement1 ; break ; case 2 : statement 2 ; : : break; default : statement } Conditional Constructs (Contd.)
  • 45. Slide 45 of 53Ver. 1.0 Programming in C Practice: 1.9 Write a function to display the following menu and accept a choice number. If an invalid choice is entered then an appropriate error message must be displayed, else the choice number entered must be displayed. Menu 1. Create a directory 2. Delete a directory 3. Show a directory 4. Exit Your choice:
  • 46. Slide 46 of 53Ver. 1.0 Programming in C Solution: Practice: 1.9 (Contd.) Microsoft Word Document
  • 47. Slide 47 of 53Ver. 1.0 Programming in C Loop Constructs The two types of conditional constructs in C are: while loop construct. do..while construct. The while loop construct has the following syntax: while (condition in true) { statement 1 ; loop statement 2 ; body } Used to iterate a set of instructions (the loop body) as long as the specified condition is true.
  • 48. Slide 48 of 53Ver. 1.0 Programming in C The do..while loop construct: The do..while loop is similar to the while loop, except that the condition is checked after execution of the body. The do..while loop is executed at least once. The following figure shows the difference between the while loop and the do...while loop. Loop Constructs (Contd.) while Evaluate Condition Execute Body of Loop True False do while Evaluate Condition Execute Body of Loop True False
  • 49. Slide 49 of 53Ver. 1.0 Programming in C Practice: 1.10 1. Write a function to accept characters from the keyboard until the character ‘!’ is input, and to display whether the total number of non-vowel characters entered is more than, less than, or equal to the total number of vowels entered.
  • 50. Slide 50 of 53Ver. 1.0 Programming in C Practice: 1.10 (Contd.) Solution: Microsoft Word Document
  • 51. Slide 51 of 53Ver. 1.0 Programming in C Summary In this session, you learned that: C language was developed by Ken Thompson and Dennis Ritchie. C language combines the features of second and third generation languages. C language is a block structured language. C language has various features that make it a widely-used language. Some of the important features are: Pointers Memory Allocation Recursion Bit-manipulation
  • 52. Slide 52 of 53Ver. 1.0 Programming in C Summary (Contd.) The types of data structures provided by C can be classified under the following categories: Fundamental data types: Include the data types, which are used for actual data representation in the memory. Derived data types: Are based on fundamental data types. Fundamental data types: char, int, and float Some of the derived data types are: short int, long int, and double float Definition of memory for any data, both fundamental and derived data types, is done in the following format: [data type] [variable name],...;
  • 53. Slide 53 of 53Ver. 1.0 Programming in C Summary (Contd.) In C language, the functions can be categorized in the following categories: Single-level functions Multiple-level functions For standard input-output operations, the C environment uses stdin, stdout, and stderr as references for accessing the devices. There are two types of constructs in C language: Conditional constructs Loop constructs

Hinweis der Redaktion

  1. Begin the session by explaining the objectives of the session.
  2. Discuss the history of the C language.
  3. The storage requirements for different data types are machine-dependent. There is a subtle difference between declaring and defining variables. The statement: char a; Is used to declare a variable a. Here, only the attributes of the variable are specified, not the contents. In contrast, the statement: char a = ‘A’ ; is used to define the contents of the variable a.
  4. Derived data types modify the data according to the specific requirements. For example, if you need to store a integer value above 32,767 or below -32,767, you can use long int instead of int . the derived data type long increases the range of the int data type.
  5. Use Slide 12 to test the student’s understanding on defining the variables.
  6. Use Slide 15 to test the student’s understanding on defining the variables.
  7. A C function is typically made up of blocks. A block is a set of C statements enclosed within braces. Variables are generally declared at the beginning of a function, but may also be declared at the beginning of a block. A C program is modular and structured. This allows for reusability of code.
  8. Use Slide 20 to test the student’s understanding on functions.
  9. Multiple-level functions are those functions where a function calls another function. Like in the slide, the main() function calls another function disp_msg() .
  10. Use Slide 25 to test the student’s understanding on functions.
  11. The getc() and getchar() functions are used to take a character from a stream. The getc() functions takes a stream as a parameter while the getchar() function does not take any parameter. Similarly, the putc() and putchar() function outputs a character to a stream. The putc() functions takes two parameters, the character to be output and the stream, while the putchar() function takes only one parameter i.e. the character to be output.
  12. Use Slide 31 to test the student’s understanding on character-based input-output functions.
  13. Use Slide 33 to test the student’s understanding on the getchar() and putchar() functions.
  14. The gets() function is used to get a string from stdin . It collects a string terminated by a new line character from the input stream. It takes a constant string as a parameter. The puts() function copies the null-terminated string, which is passed as a parameter, to the standard output stream.
  15. Use Slide 36 to test the student’s understanding on the gets() and puts() functions.
  16. Explain the need for conditional constructs and loop constructs by taking appropriate examples.
  17. Use Slide 41 to test the student’s understanding on the conditional constructs.
  18. Explain the limitations of the switch…case construct. Tell the students that the switch…case construct cannot work with float variable. Also, you cannot specify an expression in the switch…case construct.
  19. Use Slide 45 to test the student’s understanding on the conditional constructs.
  20. The condition associated with the while loop is checked before entering the loop. Hence, there is a possibility that the loop is not executed at all. In the other case, the condition is checked after executing the loop once and for every interaction thereafter.
  21. Use Slide 49 to test the student’s understanding on the loop constructs.
  22. Use Slides 51, 52, and 53 to summarize the session.