Unit 1 - PIC
Unit 1 - PIC
2 MARKS
Integer constants
Integer constants refer to the sequence of digits.
There are 3 types of integers : Decimal integers, octal integers, hexadecimal integers.
Integer constants are inadequate to represent quantities such as distances, heights,
prices etc.
Examples for integer constants are : 12, -32, 100 etc
Real constants
Real constants are the numbers with fractional parts.
Unlike Integer constants real constants can represent quantities such as distance,
heights, prices etc.
Examples for real constants are: 0.008, -0.75, 3.14 etc
13) List and specify the meaning of any four backslash character constants.
Backslash characters are used in output functions.
‘\n’ stands for newline.
‘\b’ indicates back space.
‘\0’ indicates null character
‘\t’ indicates horizontal tab
‘\v’ indicates vertical tab
20) List with use any four format codes used with scanf()/printf().
%d – Format specification for integer type data
%f - Format specification for floating type data
%c – Format specification for character type data
%s – Format specification for the string data
21) Specify the value of x after evaluating following expression
x=3+4-7*8/5%10;
x =3+4-56/5%10
=3+4-11.2%10
=3+4-1.2
=7-1.2
= 5.8
22) Specify the value of x after evaluating following expression float x =1.5;
y=3
x=y/2+y*8/y-y+x/3;
x=3/2+3*8/3-3+1.5/3
x=1.5+3*8/3-3+1.5/3
x=1.5+24/3-3+1.5/3
x=1.5+8-3+1.5/3
x=1.5+8-3+0.5
x=9.5-3+0.5
x=6.5+0.5
x=7
23) Specify the value of x after evaluating following expression int y=3, z=4, x; float
t=4.2; x=z*z/y+y/2*t+2+t;
x =4*4/3+3/2*4.2+2+4.2
=16/3+3/2*4.2+2+4.2
=5.3+3/2*4.2+2+4.2
=5.3+1.5*4.2+2+4.2
=5.3+6.3+2+4.2
=11.6+2+4.2
=13.6+4.2
=17.8
6 MARKS
1) List and Explain the features of C ?
❖ Procedural Language.
❖ Fast and Efficient.
❖ Modularity.
❖ Statically Type.
❖ General-Purpose Language.
❖ Libraries with rich Functions.
❖ Portability
❖ Easy to extend
➢ Procedural Language:
In a procedural language like C step by step predefined instructions
are carried out. C program may contain more than one function to
perform a particular task.
➢ Fast and Efficient:
Newer languages like java, python offer more features than c
programming language but due to additional processing in these
languages, their performance rate gets down effectively. It’s fast
because statically typed languages are faster than dynamically
typed languages.
➢ Modularity:
The concept of storing C programming language code in the form of
libraries for further future uses is known as modularity.
➢ Statically Type:
C programming language is a statically typed language. Meaningthe
type of variable is checked at the time of compilation but not at run
time.
function 1
function 2
. User Defined Functions
function n
➢ Documentation section:
The documentation section consists of a set of comment lines giving the
name of the program, the author and otherdetails, which the programmer
would like to use later.
➢ Link section:
The link section provides instructions to the compiler to link functions
from the system Library.
➢ Definition section:
The definition section defines all symbolic constants.
• Declaration Part:
The declaration part declares all the variables used in the executable
part.
• Executable Part:
There is at least one statement in the executable part.
➢ Subprogram Section:
The subprogram section contains all the user-definedfunctions that
are called in the main () function.
Identifiers refer to the names of variables, functions and arrays. These are user
defined names and consist of a sequence of letters and digits, with a letter as a
first character. Both upper case and lowercase letters are permitted, although
lower case letters are commonly used. The underscore character is also permitted
that is usually used as a link between two words in long identifiers.
Rules for identifiers:
1. First character must be an alphabet.
2. Must consist of only letters, digits and underscore.
3. Only first 31 characters are significant.
4. Can not use a keyword.
5. Must not contain white space.
Examples : sum, amount, name, number etc.
5) Write a note on tokens on C?
The smallest individual units in a C program are known as tokens.
• Keywords
• constants
• Strings
• Operators
• Identifiers
• Special symbols
Keywords : All keywords have fixed meanings and these meanings cannot be
the keywords must be written in lowercase.
Example: break,else,if,switch,for etc
Identifiers :Identifiers refers to the name of the variable, functions and arrays.
These are user defined names and consist of sequence of letters and digits, with
the letter as a first character.
Example : name,sum,number etc
Constants: Constant in C refers to the fixed values that do not change during
the execution of program.
a) Integer constants: An integer constant refers to a sequences of digits. There
are three types of integers namely decimal integer, octal integer & hexadecimal
Integer. Example : 121, 100, -17 etc
b) Real constants: Real constants are also known as floating point constants, are
number that have a whole number followed by a decimal point, followed by the
fraction number. Example : 3.14, 0.008 etc
c) Single character Constants: A single character constant contains single
character enclosed within a pair of a single quote marks. Example : ‘X’, ‘5’ etc.
d) String constants: A string constant is a sequence of character enclosed in
double quotes. the characters maybe letters, numbers, special characters and
blank space. Example : “abc”, “I BCA” etc.
Strings: String is a sequence of characters. String represents text rather than
numbers. It is comprised of a set of character that can also contain space and
numbers.
Ex: “hamburger” , “I ate 3 hamburgers” both are strings.
Operators: An operator is a symbol that tells the compiler to perform specific
mathematical or logical functions. C language is rich in built-in operators and
provides the operators such as arithmetic operators, relational operators, logical
operators. Example : + , /, >, && etc.
Special symbols: In c programming language the special symbols have some
special meanings and they cannot be used for other purposes.
some of the special symbols are [], (), {}, ; , *, =, #.
6) Write a note on Constants in ‘C’.
Constant is a fixed value that do not change during the execution of a program.
They are classified as:
a) Numeric constants – Integer constants and real constants
b) Character constants – Single character constants and String constants
Integer constants
Integer constants refer to the sequence of digits.
There are 3 types of integers : Decimal integers, octal integers, hexadecimal
integers.
Integer constants are inadequate to represent quantities such as distances,
heights, prices etc.
Examples for integer constants are : 12, -32, 100 etc
Real constants
Real constants are the numbers with fractional parts.
Unlike Integer constants real constants can represent quantities such as distance,
heights, prices etc.
Examples for real constants are: 0.008, -0.75, 3.14 etc
Single Character constants
A single character constant contains a single character enclosed within single
quotes.
A single character will have an equivalent integer value. For example integer
value of “A” is 65.
Examples for single character constant are : ‘X’, ‘5’, ‘+’, ‘ ‘ etc
String constants
A string constant is a sequence of characters enclosed in double quotes.
The characters may be letters, numbers, special characters and blank spaces.
Unlike single character constant string constant will not have equivalent integer
value.
Example for string constants are : “Hello!”, “1998”, “Well done”, “5+3” etc
datatype variable_name;
Here variable_name is the name of the varaible. Variables are separated by
commas. A declaration statement must end with a semicolon.