[go: up one dir, main page]

0% found this document useful (0 votes)
15 views30 pages

CPDS - Unit I.1

Uploaded by

pramodimmadi
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)
15 views30 pages

CPDS - Unit I.1

Uploaded by

pramodimmadi
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/ 30

Unit I – ALGORITHM & I/O Statements

Dr. B D V Chandra Mohan Rao


Prof. of Civil Engg.
VNRVJIET
Symbols used in Flowchart
Structure of C Program
Compiling & Running C Program
Files in C Program
Compilation & Execution Process
Compilation & Execution Process

• Source code is the file containing the C source


program. This program is input to a compiler.
• The compiler is a system software that
translates the source program to object code.
• The object code contains a equivalent set of
machine instructions corresponding to the
source program, which is understood by the
computer.
Compilation & Execution Process

• A given C program may make use of several library


functions.
• The object code of the source program is to be linked
to the object codes of the library functions.
• The Linker is a system software that links together all
the object codes to generate the final executable code.
• This executable code is submitted to the operating
system for the execution of the source program.
Compilation & Execution Process
C Character Set
White Space Characters in C
C TOKENS
Keywords in c
• Every C word is a classified as either a
“Keyword” or “Identifiers”

• Keywords serve as basic building blocks for


program statements.

• All keywords must be written in lower case.


Keywords in c
Constants in c
Integer Constants (DECIMAL)

• Constants in C refer to fixed values that do not


change during the execution of a program.
• There are 3 types of integers, namely, decimal
integers, octal integers, hexadecimal integers.
• Decimal integers consists of set of digits, 0 to 9,
preceded by an optional – or + sign. Decimal
constants are represented in base 10.
Integer Constants (DECIMAL)

• Valid Ex : 123 -123 0 +123


• Invalid Ex : 123 45 12,345 $12345
• The largest integer value that can be stored is
32767 (2^15 -1 on a 16 bit machine)
• Large integer constants can be stored by
appending qualifiers such as U, L, UL
• Ex: 123456U // unsigned integer
• Ex : 123456ul // unsigned long integer
• Ex : 123456L // long integer
Integer Constants (OCTAL)
• Octal integer constants consists of any
combination of digits from the set 0 through 7.
• Octal constants are represented in base 8 and start
with a '0' (zero) as prefix.
• Ex : 0123 // This represents 83 in decimal.
Integer Constants (Hexa decimal)

• Hexadecimal constants are represented in base 16


and start with '0x' or '0X' prefix, followed by
hexadecimal digits (0-9, A-F or a-f).
• The letters A through F represent the numbers 10
through 15.
• Ex : 0x1A; // This represents 26 in decimal
• Ex : 0x9F 0XABC 0xabc 0x
real Constants
• Used to represent the quantities such as Distance, Height,
Temperature, Price etc.
• These are also called as Floating point numbers.
• Ex : 0.0012 -0.123 123.45 +123.0
• Ex : 123. .123 -.123 +.123
• A real number is also expressed in Exponential / Scientific
form.
• Ex : 123.45 is expressed as 1.2345e2 (e2 = x10^2)
• The letter e separating the mantissa and the exponent can be
in lower or upper case.
• Ex : 0.12e2 12e-2 1.23e+3 1.23E3 -1.23E-1
Few more examples
Character Constants
• It contains a single character enclosed within a
pair of single quotes.
• Ex : ‘1’ ‘X’ ‘;’ ‘’
• Ex : printf (“%d”, ‘a’);
• Output = 97 (ASCII value of a)
• Ex : printf (“%c”, 97);
• Output = a
• As each character represents an integer value, it is
possible to perform arithmetic operations on
character constants.
Backslash Character Constants
ASCII VALUES
ASCII : American Standard Code for Information
Interchange
NUL = 0
0 = 48
9 = 57
A = 65
Z = 90
a = 97
z = 122
DEL = 127
String Constants
• It is a sequence of characters enclosed in double
quotes.
• The characters may be Letters, Numbers, Special
characters, Blank space.
• Ex : “Hello!” “123” “Well done” “1+2”
• Character constant ‘x’ is not equivalent to String
constant “x”
• Character constant has an equivalent ASCII
integer value, while single character String
constant does not have an equivalent integer
value.
Few more Examples - Constants
Type of Constants Data type Example of Data type

Integer constants
int
unsigned int 2000u, 5000U, etc.
23, 738, -1278, etc.
long int, long long int 325,647 1,245,473,940

Floating-point or Real
constants float 20.987654
doule
500.987654321

Octal constant int Example: 013 /*starts


with 0 */

Hexadecimal constant int Example: 0x90 /*starts


with 0x*/

character constants char Example: ‘X’, ‘Y’, ‘Z’

string constants char Example: “PQRS”, “ABCD”


Variables (IDENTIFIERS)
• A variable is a data name that may be used to
store a data value.
• Unlike constants that remain unchanged during
the execution of a program, a variable may take
different values at different times during
execution.
• A variable name can be chosen by the
programmer in a meaningful way.
• Consists of Letters, Digits, Underscore
• Ex : sum diff prod rem avg hft temp
VARIABLES (IDENTIFIERS)
• Identifiers refer to the names of Variables, Functions and
Arrays.
• These are user defined names and consists of sequence
of Letters and Digits, with letter as first character.
• Both Uppercase and Lowercase letters are permitted.
• The underscore character is also permitted. It is used as
a link between two words in long identifiers.
RULES FOR VARIABLES (IDENTIFIERS)
• First character must be an Alphabet.
• Consists of only Letters, Digits or
Underscore (No other special characters)
• Only first 31 characters are significant.
• Cannot use a Keyword.
• Should not contain white space.
• C is a case sensitive language.
FEW MORE EXAMPLES - vARIABLES

You might also like