0% found this document useful (0 votes)
43 views14 pages

Basics of C: S.V.Jansi Rani

This document provides an overview of the basics of the C programming language. It discusses desirable program characteristics like integrity, clarity and efficiency. It also covers C's character set, data types including int, float, double and char, and input/output functions like printf and scanf. The document describes C statements and the use of symbolic constants with the #define preprocessor directive.

Uploaded by

sudhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views14 pages

Basics of C: S.V.Jansi Rani

This document provides an overview of the basics of the C programming language. It discusses desirable program characteristics like integrity, clarity and efficiency. It also covers C's character set, data types including int, float, double and char, and input/output functions like printf and scanf. The document describes C statements and the use of symbolic constants with the #define preprocessor directive.

Uploaded by

sudhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

Basics of C

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

• Must declare a variable (specify its type and name) before


using it anywhere in your program
• All variable declarations should be at the beginning of the
main() or other functions
• A value can also be assigned to a variable at the time the
variable is declared.
int speed = 30;
char flag = ‘y’;

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

You might also like