0% found this document useful (0 votes)
192 views

Structure of C' Program

Describes basics, or just what you'd face in the beginning when you start how to construct a basic C-programming.

Uploaded by

Shubham Thakur
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views

Structure of C' Program

Describes basics, or just what you'd face in the beginning when you start how to construct a basic C-programming.

Uploaded by

Shubham Thakur
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Structure of c

Program
Constants, Variables and Data-types
A Computer Programming and Utility Project

Created By:
Shubham Thakur

Introduction
Data needs to be processed for manipulation

by user, and its response needs to be


processed by the computer for our interaction.
This processing is via the machine language
understood by the computer and its
equivalent language that can be accessed by
the humans.

Character Set
Character grouping in C:
Letters

Digits

A B C Z

0 1 2 3 4 5 6 7 `~!@#$%^_+89
=\/?

a b c z

White spaces:
Blank Space
Horizontal Tab
Carriage Return
New line
Form Feed

Special
Characters

() ][{}|<>:;,.
&*

Tri-graph Characters
Tri-graph Characters: When some symbols are

combined (in 3 in left) gives a different output


(right) shown in the table.
??=

??(

??)

??<

??>

??!

??/

??\

??-

C Tokens
Keyword
Keyword
s
s

auto
auto
break
break
case
case
const
const

Identifie
Identifie
rs
rs

X999
X999
_S93
_S93
num
num
g_nd45
g_nd45

Constants
Constants

Numeric
Numeric Constants
Constants

Character
Character
Constants
Constants

Integer
Integer
Constan
Constan
ts
ts

Real
Real
Constan
Constan
ts
ts

Single
Single
characte
characte
rr
Constan
Constan
ts
ts

+123
+123
199
199
-033
-033
0XA3
0XA3

0.082
0.082
-9.5
-9.5
+.32
+.32
1.5e+5
1.5e+5

5
5
e
e

X
X

String
String
Constan
Constan
ts
ts

\a
\a
\n
\n
\? \0
\0
\?
\\
\\

Strings
Strings

Special
Special
Symbols
Symbols

Operato
Operato
rs
rs

3Ap
3Ap
ple
ple
Black
Black
99
99
@#
@#
B49
B49

{}:_@
{}:_@
#)
#)

=+=+/!<
/!<
<<
<< >>
>>

Syntax
#include<stdio.h> //special

symbol

(#<>)

<headerfile>
double
answer=0; //keyword
identifier=numeric constant
char
name=apple; //keyword
identifier=string
a=b*c;
//variable(a)
operator(=,*)
constant (b,c)
As given in the next example, the words in
white, such as void, int, float etc. are the
keywords.

Example

Variables

Rules:

Begin with letter or an underscore(_);


Many compilers approve only first eight letters

of the variable significant, or are read by the


compiler.
Cases (up/low) are considered.
Must not be a keyword.
White spaces arent allowed.

Valid variables:
_my_name, Void, doublE, iNT, i99, _98, NaMe,
naMe, Name, etc. are different.
Invalid variables:
int, float, 99i, my name, 9_8, Na me, 99, 10th,

Data
types
ANSI C supports 3 classes of data types:

Primary/fundamental data types:


Integer type (int),
Character type (char),
Floating point (float),
Double precision floating point (double),
void void type has no values; used to specify types of functions.
Function is void if it returns no value to the calling function, it can
also represent any of he standard types.
Derived Data types:
long int,
long double

User defined data types:


Using typedef (keyword),
Using enum (keyword).

Declaration of Variables
Primary type declaration:

data-type v1,v2,vn;
Example:
int count;
int number, total;
double ratio;
int and double represents
integer & real type data values.

User Defined type declaration

typedef type identifier;


Example:
typedef int units;
typedef float marks;
units batch1, batch2;
marks m1, m2;
Here, units replaces int and marks replaces float.

User Defined type (enum)

enum identifier {v1,v2vn};


Example:
enum day {M=1,T,W,Th,F,S,Su};
enum day week_st, week_end;
week_st=M;
week_end=F;
if(week_st==T)
Week_end=S;
The compiler assigns T=2, W=3 following M=1.

Declaration of Storage class


The storage class decides the portion of the program within

which the variables are recognized.


Example:
int m;
main()
{int i;
float bal;
The variable declared as m is the global variable, because in
all the programs within the main will share the same value of
m, as it is globally declared outside main(), whereas the i,
bal are the local variable as they are declared inside the
main function.
There are 4 storage class specifier:
extern: global variable known to all functions in the file
static: local variable that exists and retains its value even

Assigning values to the variables


//The copying of one value or variable to another variable is called
assigning.
//Assignment operator (=) is used for such operation, carried out from
right to left.
//Example:
char c[40]=Hello I am a student!;//c has string length of 40 and has
copied Hello
b=40; //40 value is copied in b
a=b; //value of b is copied by a, or a holds the value 40
a=90-b; //40 value in a is erased and now the value of 90-b
a
printf(%d=a,a); //50 is printed
a=b=30; //30 is copied to b, value of b is copied to a;
a=b=20=50; //illegal assignment
a=a+1; //the value a in right sums with 1 and then is copied

is copied in

to a in left

Reading
data
from
keyboard
/*Some data has to be sent to the compiler for its computation, such
intake of values can be done by the syntax:*/
int roll; float marks; char grade, name; // local declaration
printf(Enter Roll. No., name, marks out of 50 and grade of the
student:\n);
scanf(%d %s %f %c,&roll,name,&marks,grade);
printf(\nnext comes the data accpted by the compiler:\n);
printf(%d\n%s\t%f\t%c,roll,name,marks,grade);
/*printf function helps user to interact with the compiler, about the
sequence of entering the data, and sequentially it is accepted by the
compiler using the scanf function.*/
/* output:
Enter Roll. No., name, marks and grade of the student:
50 Alex 45.003 A
next comes the data accepted by the compiler:
50
Alex45.003 A
*/

Declaring symbolic constants


//declaration of symbolic constants are preferred to be mentioned at
the start of any program
#define MAX 25

//generally identified with the capitalized letters


//used when some constants are globally accepted

#define PI 3.14

and fixed
#define num 31.4
#define Min 10

//its not wrong to write in lower case letters

//but upper case letters are preferred

//invalid declarations are:


#Define M AX 25 //white space not allowed plus D should be d in
#define
#define MAX$ 25; //no symbols and no semicolon in the end
#define MAX 25, MIN 10

//2 declarations within one #define is illegal

#define Zero=0 //assignment operator should not be used

Declaring variables as constants


/*some variables if needed can be made
constant throughout the program and hence
they will not be modified anymore using const
keyword*/
const int class_size=40; //the integer variable
class_size is declared constant
int a=b=30;
//a, b can be modified
a=class_size;
//a value is changed from 40
to 30
class_size=b;
//expression becomes illegal
//class_size can now only be used as the right

Declaring variables as volatile


/*Using the keyword volatile, it can be told to the compiler that
the variables value can be changed anywhere/anytime in
the program by the external sources outside the program*/
volatile int date=40; //date is made volatile
/*when volatile is declared on a variable, then the compiler
checks the value of date (variable) every time it encounters
eternal interruption*/
/*volatile declaration also lets the same program to change the
value of the variable. If it is required that only external
sources can modify the variable, and not by the same
program, we use const keyword.*/
volatile const int location=100;

You might also like