Basics of C: S.V.Jansi Rani
Basics of C: S.V.Jansi Rani
S.V.Jansi Rani
AP / CSE
S.V.JANSI RANI/AP/CSE/SSNCE 1
Outline
• Desirable program characteristics
• Character Set
• Data Types
• Printf
• Scanf
• Statements
• Symbolic Constants
S.V.JANSI RANI/AP/CSE/SSNCE
Desirable program characteristics
• Integrity –accuracy
• Clarity
• Simplicity
• Efficiency – speed and memory utilisation
• Modularity
• Generality
S.V.JANSI RANI/AP/CSE/SSNCE
\b, \n and \t ->special conditions such
as backspace, newline and horizontal tab, respectively – called -
escape
sequences.
S.V.JANSI RANI/AP/CSE/SSNCE
Data Types
• Each variable has a type, indicates what type of values the
variable can hold
S.V.JANSI RANI/AP/CSE/SSNCE
Four Types
1. Four common basic data types in C
–int - can store integers (usually 2 / 4 bytes)
–float - can store single-precision floating point numbers (usually
4 bytes (1 word))
–double - can store double-precision floating point numbers
(usually 8 bytes)
–char - can store a character (1 byte)
2. Enumerated types
They are again arithmetic types and they are used to define
variables that can only assign certain discrete integer
values throughout the program.
3.The type void
The type specifier void indicates that no value is available.
4.Derived types
They include (a) Pointer types, (b) Array types, (c)
Structure types, (d) Union types and (e) Function types.
S.V.JANSI RANI/AP/CSE/SSNCE
S.V.JANSI RANI/AP/CSE/SSNCE
Output- printf:
• printf (“conversion/ control string”, variable list);
• control string format
%[flags][width][.precision][length]specifier
S.V.JANSI RANI/AP/CSE/SSNCE
#include <stdio.h>
int main()
{
float z=90;
printf("%0+10.6f",z);
return 0;
}
S.V.JANSI RANI/AP/CSE/SSNCE
Input -scanf
Output- Scanf:
• scanf (“control string”, arg1, arg2, ………….argn);
• control string format
%[*][width][modifiers]type
• * is an optional argument that suppresses assignment of
the input field. That is, it indicates that data should be read
from the stream but ignored (not stored in the memory
location).
• width is an optional argument that specifies the maximum
number of characters to be read.
• modifiers is an optional argument that can be h, l or L for
the data pointed by the corresponding additional
arguments. Modifier h is used for short int or unsigned
short int, l is used for long int, unsigned long int or double
values. Finally, L is used long double data values.
• Type is same as specifier in printf()
S.V.JANSI RANI/AP/CSE/SSNCE
EXAMPLE OF printf() and scanf():
int num;
float fnum;
char ch, str[10];
double dnum;
short snum;
long int lnum;
printf(“\n Enter the values : “);
scanf("%d %f %c %s %e %hd %ld", &num, &fnum,
&ch, str, &dnum, &snum, &lnum);
printf("\n num = %d \n fnum = %.2f \n ch = %c \n
str = %s \n dnum = %e \n snum = %hd \n lnum =
%ld", num, fnum, ch, str, dnum, snum, lnum);
S.V.JANSI RANI/AP/CSE/SSNCE
Statements
• Simple statements
• Compound statements
• Control statements
S.V.JANSI RANI/AP/CSE/SSNCE
Symbolic constants
• A symbolic constant is a name that substitutes for a
sequence of characters. The characters may
represent a numeric constant, a character constant or a
string constant.
• Thus, a symbolic constant allows a name to appear
in place of a numeric constant, a character constant or a
string. When a program is compiled, each occurrence
of a symbolic constant is replaced by its corresponding
character sequence.
#define name text
#define TAXRATE 0.23
#define P I 3.141593
S.V.JANSI RANI/AP/CSE/SSNCE
THANK YOU
14
S.V.JANSI RANI/AP/CSE/SSNCE