C Notes For CP
C Notes For CP
C Notes For CP
y 1 PRIMARY CONSTANTS
No decimal point
# Real Constants ( FLOATING POINT CONSTANTS )- must at least contain one digit
both mantissa and exponent can take positive and negative values. Default sign in both is positive
# CHARACTER CONSTANTS – single digit, single alphabet or single character symbol enclosed with single
inverted commas pointed to the left.
Eg- ‘a ‘
CONSTRUCTING VARIABLE CONSTANTS
How does the computer understand what kind of variable we are formulating?
By using the following prefixes :
int – integer variable
float- real variable
char- character variable
Compiler vedor specific keywords- near, far, asm. Such keywords must
be preceded by two underscores.
FORMS OF C PRROGRAMMING
Every c program must end with ; - statement terminator
COMMENTS IN A C PROGRAM
To be enclosed within /* */
can be written after or before a statement.
Comments cannot be nested that means a comment inside another
comment is invalid.
Comment can be split over lines.
WHAT IS main()
Program containing only one function have to be named main().
All statements that belong to main are enclosed within { }
Main() function always returns an integer value hence there is an int
before main
Some compilers like turbo C/C++ admits us to return nothing from
main() therefore we precede it with the word void.
C does not have a operator function for exponentiation
Printf() and its purpose
to display output on the screen
1. To be able to use printf(), it is necessary to use #include <stdio.h>
2. General form of printf() –
printf(“<format string>” , <list of variables >) ;
PNS DOUBTS
1.A sign reads HOUSTON. Two letters are removed at random and then put back together again at
random in the empty spaces. What is the probability that the sign still reads HOUSTON?
2.Two persons throw a pair of dice once each. [That is, if persons A and B are playing then A throws a
pair of dice and then B throws a pair of dice.] What is the probability that the outcome pair of the 2
throws are same.
3.Given thirty distinguishable people, find the probability that among the 12 months of a year, there are
six containing two birthdays and six containing three. (Assume that each person is equally likely to be
born in each month of the year)
THERMO DOUBTS
1. A 5-kg piston in a cylinder with diameter of 100 mm is loaded with a
linear spring and the outside atmospheric pressure of 100 kPa. The
spring exerts no force on the piston when it is at the bottom of the
cylinder and for the state shown, the pressure is 400 kPa with volume
0.4 L. The valve is opened to let some air in, causing the piston to rise
2 cm. Find the new pressure