structure of c program. everything about the structure is in this ppt...................................................................viearhgviuehdrgbvkejfsdbvaerhbgf;oiweHFGIO;WENEGV;KLADFN;OVIBNA;OINVO;IRANV;OINDF;LNVOIASRDNGVIOERNAVB EOANGVV ERNGOEWN
2. ALGOL 1960 International Group (Europe)
BCPL (Basic Programming Combined
Lang.)
1967 Martin Richards
B 1970 Ken Thompson( first version of
UNIX)
C 1972 Dennis Ritchie (C)
History of C
1
3. History of C --- contd..
K&R C 1978 Kernighan & Ritchie
ANSI C 1989 ANSI committee
(American National Standards Institute)
ANSI/ISO C 1990 ISO committee
(International Standards Organization)
1
4. WHY LEARN
C?
C is easy to learn
C is portable
C is middle level language
5. Characteristics of C
• C Compiler Combines the features of assembly language and high-level
language
• Best suited for writing programs for system software and business
Characteristics
• High level language- Not worry about the machine code
• Small Size – C has 32 keywords
• Extensive use of function calls
• Well suited for Structed programming language
• Supports loose typing
6. Characteristics of C
• Stable language – ANSI C was created in 1983
and since then no revision
• Quick language
• Facilitates low level programming
• Core Language – C++, Java, Perl
• C is portable language
• C is an extensible language
7. USES of C
•Used System programming
•End – user application programming
12. Parts of a Program
#include <stdio.h>
int x;
int main () {
int y;
printf("Enter x and y: ");
scanf(&x,&y);
printf("Sum is %dn",x+y);
}
Preprocessor Directive
Global Declaration
Function
Local Declaration
Statements
13. Comments
Text between /* and */
Used to “document” the code for the human reader
Ignored by compiler (not part of program)
Have to be careful
comments may cover multiple lines
ends as soon as */ encountered (so no internal comments - /* An /* internal */
comment */)
// single line
14. Comment Example
#include <stdio.h>
/* This comment covers
* multiple lines
* in the program.
*/
int main () /* The main header */ {
/* No local declarations */
printf(“Too many commentsn”);
} /* end of main */
15. Files used in a C program
Files in a C program
Source
file
Header
File
Object
file
Executable
file
16. Source Code File
• Containing the source code of the program
• The file extension of the C source code is .c
• C source code file contains main function and may
be other functions
• The main() is the starting point of the c program
17. Header file
•Use same subroutine in different programs
•Compile the source code of the subroutine
once, link object file to any other program
•Header file with .h extension
18. Standard Header Files
Predefined files
String.h – string handling functions
Stdlib.h – Some library function (miscellaneous
functions)
Stdio.h – Standardized input and output functions
Math.h – Mathematical functions
Alloc.h – Dynamic memory allocation
Conio.h – Clearing the screen and character input
19. Object File
• Object files are generated by the compiler as a result
of processing the source code file
• Object file contain compact binary code of the
function definitions
• Linker uses object files to produce an executable file
by combining the object files together
• Object files - .o or .obj extension
20. Binary
Executable
File
• Binary executable file is generated by
the linker
• The linker links the various object files
to produce a binary file that can be
directly executed
• .exe extension - windows
33. KEY WORDS
• Keywords are system defined identifiers.
• Keywords are reserved words.
• They have specific meaning in the language and cannot
be used by the programmer as a variable or constant
name.
• C is case sensitive.
• 32 Keywords.
39. Basic Data Types
Data type Keywords Used Size in bytes Range Use
Character char 1 -128 to 127 To store character
Integer int 2 -32768 to 32767 To store integer number
Floating
Point
float 4 3.4E-38 to 3.4E+38 To store decimal number
Double double 8 1.7E-308 to 1.7E308 To store big floating-point number
Valueless void 0 Valueless -
48. VARIABLES
A variable is a container(storage area) to hold
data.
All variables have three important attributes:
data type
name
value
Eg: int a = 10;
float b = 2.5;
char c = ‘f’;
49.
50. CONSTANT
A constant is a value or an identifier whose value cannot be
altered in a program. For example: 1, 2.5
An identifier also can be defined as a constant. eg. const double
PI = 3.14
Here, value of PI is a constant.
51. Constant
Declaration
● To declare a constant, precede the normal variable
declaration with const keyword and assign it a value.
● For example,
const float pi = 3.14;
● Another way to designate a constant is to use the
pre-processor command define.
#define PI 3.14159
When the preprocessor reformats the program to be
compiled by the compiler, it replaces each defined
name with its corresponding value wherever it is
found in the source program.
52. TYPES OF CONSTANTS
Integer constant eg: 1
Floating-point constant eg: 2.5
Character constant eg: ’a’
String constant eg: ”good”
54. STREAMS
● A stream acts in two ways. It is the source of data as well as the destination of data.
● C programs input data and output data from a stream. Streams are associated with a physical device such as
the monitor or with a file stored on the secondary memory.
● In a text stream, sequence of characters is divided into lines with each line being terminated with a new-line
character (n). On the other hand, a binary stream contains data values using their memory representation.
● Although, we can do input/output from the keyboard/monitor or from any.
Streams in a C program
Text Stream
Binary Stream
Keyboard Data
Monitor Data
Input text stream
Input text stream
59. Parts of conversion specifier field for
printf()
The percent sign and conversion code
are required
Other modifiers such as width and
precision are optional.
width specifies the total number of
characters used to display the value
precision indicates the number of
characters used after the decimal
point. The precision option is
only used with floats or strings.
Default precision value is 6
62. Example
# include <stdio.h>
int main()
{
printf(“number=%3dn”, 10);
printf(“number=%2dn”, 10);
printf(“number=%1dn”, 10);
printf(“number=%7.2fn”, 5.4321);
printf(“number=%.2fn”, 5.4391);
printf(“number=%.9fn”, 5.4321);
printf(“number=%fn”, 5.4321);
}
63. Flag characters used in printf()
Flag Meaning
- Left justify the display
+ Display positive or negative sign of value
Space Display space if there is no sign
0 Pad with leading zeros
# Use alternate form of specifier
67. 2. Unformatted Input/output functions
Input functions
gets()
getchar()
getch()
getche()
Output functions
puts()
putchar()
putch()
puts()
•The I/O library functions are listed in the
“header” file <stdio.h>.
•Types:
•Unformatted Input/output functions
•Formatted Input/output functions
•
1. Data Input and Output
68. getchar()
Reads a single character from the input data
stream; but does not return the character to
the program until the ‘n’ ( or ) enter key is
pressed.
Syntax:-
variable = getchar();
Example:-
char c;
c = getchar();
Program
#include<stdio.h>
void main()
{
char c;
printf(“Enter a character”);
c=getchar();
printf(“c = %c ”,c);
}
Output
Enter a character k
c = k
69. getch() and getche()
These functions read any alphanumeric character from
the standard input device
The character entered is not displayed by the getch()
function until enter is pressed
The getche() accepts and displays the character.
The getch() accepts but does not display the character.
Syntax:
getche();
getch();
70. getch() and getche() - Program
#include<stdio.h>
void main()
{
printf(“Enter two alphabets:”);
getche();
getch();
}
Output
Enter two alphabets a b
a
71. putchar()
This function prints one character on the
screen at a time which is read by standard
input.
Syntax:
putchar( variable name);
Example:
char c= ‘c’;
putchar(c);
#include<stdio.h>
void main()
{
char ch;
printf(“Enter a character: ”);
scanf(“%c”, &ch);
putchar(ch);
}
Output
Enter a character: r
r
72. putch()
This function prints any
alphanumeric character taken
by the standard input device
Syntax:
putch( variable name);
Example:
char c= ‘c’;
putch(c);
Program
#include<stdio.h>
void main()
{
char ch;
printf(“Press any key to
continue”);
ch = getch();
printf(“ you pressed:”);
putch(ch);
73. gets()
String I/O
This function is used for accepting any
string( stream of characters) until enter
key is pressed
Syntax
char str[length of string in number];
gets(str);
Example:
char name[15];
gets(name);
Program
#include<stdio.h>
void main()
{
char ch[30];
printf(“Enter the string:”);
gets(ch);
printf(“Entered string: %s”, ch);
}
Output:
Enter the string: Use of data!
Entered string: Use of data!
74. puts()
This function prints the string or
character array.
It is opposite to gets()
Syntax
char str[length of string in number];
gets(str);
puts(str);