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

CHAA

KNNK

Uploaded by

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

CHAA

KNNK

Uploaded by

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

MCS011(Problem Solving and Programming)

Block-1 (AN INTRODUCTION TO C)


Unit-3 (VARIABLES AND CONSTANTS)

•Character Set
•Identifiers and Keywords
•Data Types and Storage
•Data Type Qualifiers
•Variables
•Declaring Variables
•Initializing Variables
•Constants
•Symbolic Constants

Character Set
Every character set contains a distinct code value for each character in the basic C character
set.

Identifiers
Identifiers are the names given to various program elements such as constants, variables,
function names and arrays, etc.
Keywords
Keywords are reserved words that have standard, predefined meanings in C. They cannot be
used as program-defined identifiers.
Data Types and Storage

Data Type Qualifiers


Short, long, signed, and unsigned are called the data type qualifiers and can be used with any
data type

Variables
Variable is an identifier whose value changes from time to time during execution. It is a named
data storage location in your computer's memory.
All variables have three essential attributes:
• the name
• the value
• the memory, where the value is stored.
Declaring Variables
•Before any data can be stored in the memory, we must assign a name to these locations of
memory.

The syntax for declaring variables is as follows:


Datatype
variable-name(s)

For example,
int a;
short int a, b;
Variables and Constants int c, d;
long c, f;
float r1, r2;

Initializing Variables
When variables are declared initially, values can be assigned to them in two ways:

a) Within a Type declaration


The value is assigned at the declaration time.

For example,
int a = 10;
float b = 0.4 e –5;
char c = ‘a’;

b) Using Assignment statement


The values are assigned just after the declarations are made.
For example,
a = 10;
b = 0.4 e –5;
c = ‘a’;

Constants
•A constant is an identifier whose value can not be changed throughout the execution of a
program whereas the variable value keeps on changing.

•In C there are four basic types of constants.


1. Integer constants
2. Floating point constants
3. Character constants
4. String constants

Integer Constants
1. Decimal integer constants
2. Invalid Decimal integer Constants
3. Octal integer constants
4. Hexadecimal integer constants
5. Valid Hexadecimal integer constants are:
6. Invalid Hexadecimal integer constants are:
7. Unsigned integer constants:
8. Long Integer constants

Floating point Constants

•valid floating point numbers


•Invalid Floating Point
Character Constants
•This constant is a single character enclosed in apostrophes ''

ESCAPE SEQUENCE
•There are some non-printable characters that can be printed by preceding them with '\'
backslash character.
String Constants
•It consists of a sequence of characters enclosed within double quotes.

Symbolic Constants
Symbolic Constant is a name that substitutes for a sequence of characters or a numeric
constant, a character constant or a string constant.

The syntax is as follows: Variables and Constants


#define name text where name implies symbolic name in caps.
the text implies value or the text.
For example,
#define printf print
#define MAX 100
#define TRUE 1
#define FALSE 0
#define SIZE 10

You might also like