UNIT 1 Notes
UNIT 1 Notes
INTRODUCTION TO C PROGRAMMING:
- C is a general-purpose computer programming language developed in 1972 by Dennis M.
Ritchie at the Bell Telephone Laboratories to develop the UNIX Operating System. - C is
also called mother Language of all programming Language. It is the most widely use
computer programming language.
- All other programming languages were derived directly or indirectly from C programming
concepts.
- This language is used for develop system software and Operating System.
Features of C:
Simplicity:
- It is very easy to understand.
Portability:
- It is the concept of carrying the instruction from one system to another system
Powerful:
- C is a very powerful programming language, it have a wide verity of data types, functions,
control statements, decision making statements, etc
Structure oriented:
- Structure oriented programming language aimed on clarity of program, reduce the
complexity of code, using this approach code is divided into sub-program/subroutines.
These programming have rich control structure.
Modularity
- In c programming we can break our code in subprogram.
Middle level language:
- C programming language can supports two level programming instructions with the
combination of low level and high level language that's why it is called middle level
programming language
Compiler based:
-C is a compiler based programming language that means without compilation no C
program can be executed
printf(“good morning\n”);
printf is a build-in functions which is used to display output in the screen. \n is
called escape sequence to go to next line It always begin with \ (back slash).
Semicolon(;)
It is used to terminate the statement.
return(0);
- This statement terminates the main function.
- Returns the value 0 to the operating system indicating Successful completion of program.
- Any other number indicates that the program is failed.
Digits: 0 to 9.
White spaces characters int age; // balnk space between int and age is ignored
by compiler. It is used to distinguish the aqw.
(ii)Execution Character set:
Horizontal tab \t
Vertical Tab \v
Null Character \0
C TOKENS:
∙C tokens are the basic buildings blocks in C language which are constructed together to
write a C program.
IDENTIFIERS:
Identifiers are the name used to identify entities like variable, function, array, structure or any
other user-defined item.
Identifier must be unique.
They are created to give unique name to an entity to identify it during the execution of the
program.
Rules for naming an Identifier
∙ Identifier name in C can have letters, digits or underscore(_).
∙ The first character of an identifier name must be a alphabet (a-z, A-Z),underscore( _ ). ∙
The first character of an identifier cannot be a digit.
∙ Keywords are not allowed to be used as Identifiers.
∙ No special character (except underscore) blank space and comma can be used in Identifier
name.
KEYWORDS
∙ Keywords are reserved words that have a particular meaning in C language. ∙ The
meaning of key word is predefined. These meaning of the keyword cannot be changed.
∙ There are total 32 keywords in C language.
VARIABLES:
It is a name given to the memory location.
In programming, a variable is a container (storage area) to hold data. To indicate the
storage area, each variable should be given a unique name called identifier.
Example,
int a=20;
L-Value: R-Value
The L-Value Could Legally Stand On The Left Side R-value can be anything of
Of An Assignment Operator. following: 1.Variable
For Example: Mark=20; // 2.Function
The L- Value Should Be A Variable. 3. Constant
Eg,
num=20; //constant R value
Example:
Addition of two numbers: Output:
#include< stdio.h> Sum is 100
int main()
{
int a,b,c; //Variable declaration
a=50; //Assigning values to variables
b=50;
c=a+b;
printf("sum is %d",c);
return(0);
}
DATA TYPES :
Data types determines the possible values that an identifier can have and the valid
operations that can be applied on it.
The type of a data determines how much space it occupies in storage.
In C Language, data types are broadly classified as
Floating type
Float data type is used to store real numbers.
10
Double 8 1.
longdouble 10 3.4
Character type
Type S
- Character denotes any alphabet, digit or special symbol to represent information. -
Key word is char.
- Size of character is 1 byte. Eg, char a=‘h’;
char or signed char 1 -128 to
11
12
printf("%d",m1);} m1=MAY;printf("%d",m1)
Output: ;} Output:
3 3
Explanation: Explanation:
In this example, we Integers are assigned to enum
declared “m1” as the constants.
variable and the value of
“APRIL” is allocated to
m1, which is 3.
13
Output:
16.100000
STORAGE CLASS:
A storage class defines the scope (visibility) and life-time of variables.
Scope - Where to store a variable (Storage area of variable)
Lifetime- How long the variable can be stored in the memory( alive)
The following storage classes are most often used in C programming.
1.auto 2.static
3.extern 4.register
A variable should be declared in any one of these four storage class.
Syntax: Example:
auto data_type variablename; (or) auto int a;
14
data_type variable; int a;
(both are same since auto is
default storage class )
Syntax: Example:
static data_type variablename; static int a;
Note: Memory occupied by the variable will be released only after completion of the program.
Syntax: Example:
extern datatype variablename; extern a=10;
Syntax: Example:
register data_type variablename; register int a;
16
}
int increment()
{
register int a=10;
a++;
printf("Value of a is: %d\n", a);
}
CONSTANTS (LITERALS):
Constants are the values that cannot be changed during the execution of a program. Constant
is a fixed value which may be an integer, floating point number, character or a string. Types of
constants:
∙ Integer constants:
- Integer constants are integer values like -1, 2, 8 without any decimal point. - It can be
either positive or negative. If no sign proceeds an integer is assumed to be positive.
There are three types of integer constants in C language:
- Decimal constant (base 10)
- Octal constant (base 8)
- Hexadecimal constant (base 16)
17
∙ Floating-point constants:
- Floating point constants can be written in fractional form or exponential form. Floating
point constant are values like -23.1, 12.8, -1.8e12.
- The floating point constant in an exponential form has two parts: The mantissa part and
the exponent part. Both parts are separated by e or E.
∙ Character constants:
- Character constants can have one character enclosed within single quotes. -
For example: 'a', 'l', 'Y', 'A' etc.
Escape Sequences
- C supports some special character constants that are used in output functions. -
Escape sequence consists of a backward slash (\) followed by a character.
Escape Sequences Character
\n Newline
\a Alert
\t Horizontal tab
\v Vertical tab
\\ Backslash
\? Question mark
\0 Null character
∙ String constants
- String constant can have group of characters enclosed within double quotes.
For example: “hai”, “welcome”
Declaring a variable as constant:
Syntax:
const datatype variable = constant
Example:
const float PI=3.14;
Program using const Output To find area of rectangle Output
keyword: error using const keyword. area : 70
#include<stdio.h> [const value #include <stdio.h>
int main() cannot be changed. int main()
{ {
18
OPERATORS IN C:
Operands:
∙An operand specifies an entity on which an operation is to be performed.
∙An operand can be a variable name, constant, a function call.
Operators:
∙Operators are special symbol that tells the compiler to perform specific mathematical or
logical operations.
∙Operator specifies the operation to be applied to its operands.
CLASSIFICATION OF OPERATORS:
The operators in c are classified on the basis of the following criteria:
1. The number of operands on which an operator operates.
2. The role of an operator.
Classification based on Number of Operands
Based upon the number of operands on which an operator operates,operators are classified
as,
Unary operator: Binary operator ternary operator
A unary operator operates Binary operator operates Ternary operator operates on three
on only one operand. on two operands. operands. (Conditional operator)
Assignment Operators
A variable can be assigned a value by using an assignment operator. The assignment operators
are available in c are given below.
Operator Description Example
+= addsright operand to the left operand and assign the a+=b is same as
result to left a=a+b
-= subtracts right operand from the left operand and assign a-=bissameas a=a-b
the result to left operand
*= multiply left operand with the right operand and assign a*=b is same as
the result to left operand a=a*b
/= divides left operand with the right operand and assign the a/=bissameas a=a/b
result to left operand
20
c %= a;
printf("c=%d \n", c); return 0;
}
Relational operators:
- Relational operators are used to check the conditions.
- If the relation is true, it returns 1; if the relation is false, it returns value 0. -
The operand may be variables, constants or expressions.
Operator Description Example program Output
:
Logical operators:
- Logical operators are used to combine the results of two or more conditions. C has the
following logical operators.
O Description Example a=5, b=2
p
era
tor
&& Logial AND. True only if all operands are true ((a == 5) && (b > 5)) equals to 0.
|| Logical OR. True only if either one operand is true ((a == 5) || (b > 5)) equals to 1.
Bitwise operators:
- Bitwise operators perform manipulations of data at bit level.
- It operates on individual bits of the operands.
- Bitwise operators are not applicable for float or double data types.
21
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Assume A = 60 and B = 13 .
In binary format, A= 0011 1100 and B = 0000 1101
Operator Description A= 0011 1100 and B = 0000 1101
First the value of operand is The value of operand is used for the
incremented by 1 and then it is used evaluation of the expression and then
for evaluation of the expression. it is incremented.
Decrement operator:
- Decrement operator is used to decrement the value by subtracting 1.
- The value of i-- is equal to i=i-1.
Decrement operator can be classified into two types.
pre decrement operator
post decrement operator
22
First the value of operand is The value of operand is used for the
decremented by 1 and then it is used evaluation of the expression and then
for evaluation of the expression. it is decremented.
Special Operator:
Operator Description Example
* Pointer to a variable *x ;
Example: Output:
#include <stdio.h> Size of integer is 2
int main() Size of Float value
{ is 4 Size of character
int a;float b;char c; is 1
printf("Size of integer is %d\n", sizeof(a));
printf("Size of Float value is %d\n", sizeof(b));
printf("Size of character is %d\n", sizeof(c)); }
Conditional operator:
Conditional operator is the ternary operator.
Syntax:
Condition? Expression 1: Expression
2
Condition: condition is checked first. This expression evaluates to 1 if it's true and evaluates to
0 if it's false.
23
Expression1: If the condition is true, this expression is evaluated and return the result of
Expression1.
Expression2: If the condition is false, this expression is evaluated.
Advantages of ternary operator:
Using ?: reduce the number of line codes and improve the performance of application.
Example 1: Use of Example 2: Use of ternary operator
ternary operator
#include <stdio.h> #include<stdio.h>
int main() main()
{ {
int a=89,b; int a=10,b=20,small;
b=(a ==100?1:2); printf((a<b ? printf("a is less") : printf("a is
greater"))); return(0);
printf("%d\n",b);return(0); }
} Output:
Output: a is less
2
PRECEDENCE OF OPERATORS:(Associativity)
▪ Each operator in c has a precedence associated with it..
▪ High precedence operator *, /,%.
▪ Low precedence operator +, -.
Precedence rule: This rule decides the order in which different operators are applied.
Associativity rule: Thisrule decidesthe orderinwhich multiple occurrence of the same
level operators are applied.
Several operators of the same precedence appear together, the operator are evaluated
according their associativity.
If the operators are left-to-right associative, they are applied in left-to –right order.
If the operators are right-to-left associative, they are applied in right-to-left order.
This table lists C operators in order of precedence (highest to lowest) and their
associativity.
Operator Description Associativity
++ Increment right-to-left
-- decrement
+ Unary plus
- unary minus
& Address of operator
sizeof Determine size in bytes on
this implementation
24
*
Multiplication
left-to-right
/
Division
%
Modulus
+ Addition left-to-right
- Subtraction
|| Logical OR left-to-right
Examples:
a=9-12/3+3*2-1 int a; a=2*3+4%5-3/2 int a=
a=? a=2*3.25+((3+6)/2) +6 a=? 5+7*4-9*(3,2) a=?
a=9-4+3*2-1 a=? a=6+4-3/2+6 a= 5+7*4-9*2
a=9-4+6-1 a=2*3.25+9/2 a=6+4+1+6 a=5+28-18
a=5+6-1 a=6.50+4 a=10-1+6 a=33-18
a=11-1 a=10.50 a=9+6 a=15
a=10 a=10 a=15
(because ‘a’ is an integer)
25
EXPRESSIONS:
Expressions:
An expression is a sequence of operands and operators.
The meaningful expression consists of one or more operands or operators that specify
the operations to be performed on operands.
Example: a+b, a-b.
Operands:
An operand specifies an entity on which an operation is to be performed.
Operators:
Operators are special symbol that tells the compiler to perform specific mathematical or logical
operations.
Operator specifies the operation to be applied to its operands.
Based on the number of operators present in an expression, expressions are classified as
simple expression and compound expressions.
Simple expressions:
An expression that has only one operator is known as a simple expression
For example: a+2;
Compound Expressions:
An expression that has more than one operator is known as compound expressions.
For example: b= 2+3*5;
INPUT AND OUTPUT STATEMENTS:
In c language two types of input/output statements are available. They are
1. Formatted input/output statements
2. Unformatted input/output statements
26
scanf() statement:
scanf() is a built-in library function in c.
It is a standard input function used to read inputs from the user during execution of the
program.
Syntax:
scanf(“control strings”,&variable1,&variable2….&variable);
%c Single character
%s String
%d Integer
%f Float
%ld Double
Example:
printf(“hello my dear friend”);
(ii) printf() is used to print the value of the variable and results of the expressions.Using
format specifier
Syntax:
printf(“control string”, variable1,variable2..);
Example:
printf(“my age is %d”, age)
Control strings(Format Specifier):
- Control string is the type of data that the input statement going to accept, this always
preceded with a % sign.
printf() for integer datatype:
Example:
printf(“%d%d”,a,b); // here a and b variables holding integers.
printf() for float datatype:
Example:
printf(“%f%f”,a,b); //here a and b are variables holding float values.
28
29
30
{ The Temperature in
float celsius, fahrenheit; Fahrenheit is:50.000000
printf ("Enter the Temperature in Celsius:");
scanf ("%f", &celsius);
fahrenheit = (1.8 * celsius) + 32;
printf ("The Temperature in Fahrenheit is:%f",
fahrenheit); return(0);
}
31
Syntax: input.
variable name=getchar(); Syntax:
Example putchar(variable_name);
char c; Example:
c=getchar(); char c;
putchar(c );
getch() putch()
- getch() accepts only single character from It displays any alphanumeric characters to
keyboard. the standard output device. It displays only
- getch() function will just wait for any one character at a time.
keyboard input (and press ENTER). It Syntax:
won’t display the given input character in putch(variable_name)
output screen. Example:
Syntax: char a;
variable_name=getch(); putch(a);
Example:
char x;
x=getch();
Program using getch() function:
#include <stdio.h>
int main()
{
printf("Hello World! ");
getch();
return 0;
}
Output:
Hello World!
32
getche()
Like getch(), getche() also accepts only single character, but getche() displays the entered
input character in the screen.
Syntax:
Variable_name=getche();
Example:
char x;
x=getche();
To use getch(), getche() functions, you need to include #include <conio.h> header file
which is a non-standard header file.
gets() puts()
- gets() accepts any line of string including puts displays a single / paragraph of text to
spaces from the standard Input device the standard output device.
(keyboard). Syntax:
-gets() stops reading character from puts(variable_name);
keyboard only when the enter key is Example:
pressed. char name[25];
Syntax: puts(name);
gets(variable_name);
Example:
char name[25];
gets(name);
Program to read and print the string using
gets and puts:
#include<stdio.h>
main() Output:
{ enter the string
char name[20]; hello my friend
printf("enter the string\n"); hello my friend
gets(name);
puts(name);
return(0);
}
33
Program to convert character from lower case to uppercase and vice versa:
#include<stdio.h> Output 1:
int main() enter the character
{ g
char a; G
printf("enter the character\n"); Output 2:
a=getchar(); enter the character
if(islower(a)) G
putchar(toupper(a)); g
}
else
{
putchar(tolower(a));
} return(0);
}
1 These are standard input output library These are console input output library function.
. function.
2. Formatted input and output functions Unformatted input/output can deal with one
can deals with all kind of data types. character at a time and string function for array
of characters (string).
3. Unformatted Input / Output functions Formatted Input / Output functions are several
have fixed format to give the input and standard library functions
obtain the output.
1. if statement
▪ If the condition is true, the statements inside if statement will be executed. ▪ If the
condition is false, the control will be transferred to the statements outside of if.
2. if...else statement
∙ In this, else statement can be combined with if statement.
∙ If Condition is checked first.
∙ If the condition is true, statements inside the if part is executed
∙When the condition is false, statements in else part is executed.
35
36
Leap year or not: Output:
#include <stdio.h>
int main() Enter a year
{ 2016
int year; leap year
printf("Enter a year\n");
scanf("%d", &year);
if ((year%4 == 0) && (year%100!=0)||
(year%400==0)) printf("leap year.\n");
else
printf("not a leap year.\n");
return(0);
}
Note:
A year is leap year if following conditions are
satisfied 1) Year is multiple of 400
2) Year is multiple of 4 and not multiple of 100.
If
'expression' is false the 'statement-3' will be executed, otherwise it continues to check the condition
for 'expression 1' .
If the 'expression 1' is true the 'statement-1' is executed otherwise 'statement-2' is executed
37
4.else-if ladder :
∙ If there are more than three alternatives, we can go for else if ladder.
∙ Once a true condition(if) is satisfied, the other statements in the ladder will be skipped. ∙ When all
conditions became false, then the final else part which contains default statement will be executed.
38
39
}
else
printf("Root are imaginary\n");
}
Program to find the entered key is an alphabet or Output:
numeric or alphanumeric(using character Build-in Enter any key
functions) #include<stdio.h> 8
int main() Entered key is number
{
char a;
printf("Enter any key\n");
a=getchar();
if(isdigit(a))
printf(" Entered key is number");
else if(isalpha(a))
printf("Entered key is alphabet");
else
printf("Entered key is alphanumeric");
return(0);
}
Note:
In if statement, a single statement can be written without using curly braces
{ } Eg, int x=2;
if(x > 4)
printf("welcome");
In the above case, no curly braces are required, but if we have more than one statement inside if
condition, then we must use curly braces.
Other than 0(zero), all other values are considered as true.
Eg, if(9)
printf("welcome");
In above example, hello will be printed, because the integer 9 is a non zero value.
40
Switch statement:
C provides a multi way decision statement called switch statement.
It allows the user to make a decision from number of choices.
The expression(condition) in switch case return an integer value or character constant,
which is compared with the values in different cases.
When the condition matches with the case ,that block of statement is executed.
If there is no match, then default statement is executed.
Note:
It isn't necessary to use break after each block, but if you do not use it, all the consecutive block of
codeswillget executedafterthematchingblock.
int i = 1;
switch(i)
{
case 1:
printf("A"); //No break case 2:
printf("B"); //No break case 3:
printf("C");
break;
}
Output : A B C
- The output was supposed to be only A because only the first case matches, but as there
isnobreak statementaftertheblock,thenextblocksareexecuted,untilthe cursor encounters a break.
Rules for switch Statement:
o Default case is optional andcanbeplaced anywhere inthe switchcase. But Usually we place it at
the end.
41
42
break;
case 4 :
printf("Division is %d : ",a/b);
break;
default :
printf(" Enter Your Correct Choice.");
break;
}
return(0);
}
Printing student GPA details using switch case: Output:
#include<stdio.h> Enter three subject
int main() Marks95
{ 94
int m1,m2,m3,gpa; 96
float tot, avg; grade=A
printf("Enter three subject Marks");
scanf("%d%d%d",&m1,&m2,&m3);
tot=m1+m2+m3;avg=tot/3; gpa=avg/10;
switch(gpa)
{
case 10: printf("grade=S"); break;
case 9 : printf("grade=A"); break;
case 8 : printf("grade=B"); break;
case 7 : printf("grade=C"); break;
case 6 : printf("grade=D"); break;
case 5 : printf("grade=E"); break;
default : printf("grade=F");
}
return(0);
}
The test condition is checked first before The loop is executed first and then
the loop is executed. condition is checked.
43
while Loop:
It is an entry controlled looping statement.
Statements are executed repeatedly until the while condition is true.
It is completed in 3 steps.
✔ Variable initialization. ( e.g int x=0;)
✔ Condition Checking ( e.g while( x<=10) )
✔ Variable increment or decrement ( x++ or x-- or x=x+2)
Description:
Step 1: The while condition is checked first.
Step 2: If the condition is true, the statements inside the loop will be executed, then the variable
value is incremented or decremented at the end of the looping statement.
Step 3: If the condition is false, the loop body will be skipped and the statements after the while
loop will be executed.
44
Sum of Digits of given number using while Output:
loop: #include <stdio.h> enter the number
int main() 555
{ sum of digits of given no is: 15
int n,dig,sum1=0;
printf("enter the
number\n");scanf("%d",&n); while(n>0)
{
dig=n%10;
sum1=sum1+dig;
n=n/10;
}
printf("sum of digits of given no is:
%d",sum1); return(0);
}
}
if(rev == n )
printf("It is a palindrome no.\n"); else
printf("it is not a palindrome no.\n");
return(0); }
do whileloop:
It is an exit controlled looping statement.
The do-while loop checks its condition at the bottom of the loop whereas for and while loops,
the loop condition is checked at the top of the loop.
do-while loop is guaranteed to execute the statement at least one time.
46
While Do while
47
for loop:
forloopisusedtoexecuteasetofstatementsrepeatedlyuntilaparticularconditionis satisfied.
Flow of Execution:
i.The initialization step is executed first, and only once. This step allows to declare and
initialize any loop control variables.
ii.Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false,
the body of the loop will not be executed and flow of control jumps to the next statement
just after the for loop.
iii.After the body of the for loop executes, the flow of control jumps back up to the
increment statement. This statement allows to update any loop control variables. iv.The
condition is now evaluated again. If it is true, the loop executes and the process repeats itself
(body of loop, then increment step, and then again condition). When the condition becomes
false, the for loop terminates.
Different ways of implementing for loop:
Form Comment
for ( i=0 ; i < 10;i++) ; For Loop with no Body ( Carefully Look
at the Semicolon )
48
for(i=0,j=0;i<100;i++,j++) Multiple initialization & Multiple
Statement1; Update Statements Separated by Comma
49
50
{
int i, n, a = 0, b = 1, next;
printf("Enter the number of terms: ");
scanf("%d", &n);
for (i = 1; i <= n; ++i)
{
printf("%d,",a);
next=a+b;
a=b;
b=next;
}return 0;
}
To find Factors of a given number: Output:
#include<stdio.h> Enter a number to find
int main() its factors
{ 10
int n,i; factors are: 1
printf("Enter a number to find its factors are: 2
factors\n"); scanf("%d",&n); factors are: 5
for (i=1;i<=n;i++) factors are: 10
{
if(n%i==0)
printf("factors are: %d\n",i);
}
return(0);
}
51
52
2) continue statement:
C Continue statement are used to skips the rest of the current iteration in a loop and returns to
the top of the loop.
Syntax:
continue;
53
Example:
Use of break statement to Output: Use of continue statement Output:
print numbers: to print numbers:
#include <stdio.h> enter the enter the
int main() number: #include <stdio.h> number: 10
{ int main()
10 1 1
int i,num; {
2 2
printf("enter the number: int i,num;
"); scanf("%d",&num); 3 printf("enter the number: 3
for(i=1;i<=num;i++) 4 "); scanf("%d",&num); 4
{ for(i=1;i<=num;i++) skipped
if(i==5) { 6
{ if(i==5) 7
printf("stop"); {
8
break; printf("skipped\n");
continue; 9
}
printf("%d\n",i); } 10
} printf("%d\n",i);
return(0); }
} return(0);
}
Break Continue
Break statement is used to transfer the Continue is used to skip some statement
controloftheprogramtooutsideloopor of the loop and moves to the next
switch case statement. iteration in the loop.
It is used in loop as well as switch case. It is used only within the loop.
3) goto statement:
❖The goto statement is used for altering the normal sequence of program execution by
transferringcontrolto some other part ofthe program.
❖When a goto statement is encountered in a C program, the control jumps directly to the
label mentioned in the goto statement.
❖It us used when loops are deeply nested and simple break statement cannot work
effieciently.
Syntax:
goto label_name;
…
…
label_name
54
Preprocessor Directives:
Preprocessor is a program which will be executed automatically before passing the source
program to compiler. This process is called pre-processing.
The preprocessor provides the ability for the inclusion of header files, macro expansions,
conditional compilation, and line control.
Commands used in preprocessor are called preprocessor directives.
They begin with "#" symbol and should be not ended with (;)
Proprocessor Directive can be place any where in the program, but generally it place top of the
program before defining the first function.
Preprocessor directives in C:
∙ Macro substitution directives. example: #define
∙ File inclusion directives. example: #include
∙ Conditionalcompilation directive. example: #if, #else, #ifdef, #undef, #endif
∙ Miscellaneous directive. example: #error, #line
55
(i)Macro preprocessor:
Example: To print PI value
#include<stdio.h>
#define PI 3.14
int main()
{
printf("%f",PI);
}
Three types of macros are
Simple macros Augmented macros Nested macros
(ii)File Inclusion:
This is used to include an external file which contains functions into the program. It enables code
reusability.
Syntax Example
∙The filename is quoted in quotes (“ ”), then it searches that file in current directories. ∙When
the filename is quoted in angle brackets (< >), then it searches the file in standard directories
only.
(iii)Conditional Directives:
#if, #else and #endif:
If given condition is true, "If" clause statement is included in source file . Otherwise, else clause
statement is included in source file for compilation and execution.
56
Example: Tocheck the Vote eligibility using #if, #else and #endif
#include<stdio.h> Output:
#define AGE 5 Not eligible
int main()
{
#if (AGE>=18)
{
printf("Eligible for voting");
}
#else
{
printf("\n Not eligible");
}
#endif
return(0);
}
undef
This directive undefines existing macro in the program.
In below program we first undefine age variable and again it is defined with new value.
Example: Undefining the macro Output:
#include<stdio.h> First define value for age
#define age 20 is: 20
57
PART A:
1. What are variables? Give Examples (M/J’16)(N/D’14)
2. Define implicit type conversion (M/J’16)
3. What is an array? Give Example (M/J’16) (M/J’15)
4. Define strings. Give examples(M/J’16)
5. What is meant by linking process? (N/D’15)
6. What are the input functions and output functions in C? (N/D’15) (M/J’15) 7.
Write a C program to store Fibonacci series in an array. (N/D’15) 8. List the string
functions available in C. (N/D’15)
9. List some pre-processor directives. (N/D’15)
10. What are the importance of keyword in C? (M/J’15)
11. How is a character string declared? (M/J’15)
12. Give the use of pre-processor directives. (M/J’15) (N/D’14) (M/J’14)
13. Give an Example of ternary operator. (N/D’14)
14. Describe float array of size 5 and assign 5 values in it. (N/D’14)
15. Give an example for initialization of string array.
16. Define static storage class. (N/D’14)
17. List different data types available in C. (M/J’14)
18. Write a C program to find factorial of the number using iteration. (M/J’14)
19. Write an example code to declare two dimensional array. (M/J’14) 20. List
any 4 string handling functions (M/J’14)
PART B:
1. Explain different types of operators in detail.(M/J’16) (M/J’15) (N/D’14)
2. Discuss basic data types in C (M/J’16)
3. Describe various input and output statements in detail. (M/J’16)
4. Write a C program for the following series 1+2+3+4+…N (M/J’16) 5. Write a C
program to convert the number of vowels in your name (M/J’16) 6. Write a C program to
multiply two matrices/ Write a C program for two 3*3 Matrix (M/J’16)/(N/D’15)
(N/D’14)
7. Write a C program to check whether the given string is palindrome or not(M/J’16) 8. Write
a C program to arrange the given 10 numbers in descending order (M/J’16 9. Explain various
storage classes in detail. (M/J’16) (N/D’15) (M/J’15) (M/J’14) 10. Describe about
pre-processors with suitable examples. (M/J’16)
58
11. Describe the structure of C program using ‘calculator program’ example. (N/D’15)
12. Write short notes on branching statements in C. (N/D’15)
13. Write in detail about various looping statements with suitable example.(N/D’15) (M/J’15)
(N/D’14)
14. Write a C program to find determinant of the resultant matrix. (N/D’15)
15. Write the following programs (N/D’15)
(i) To sort the given set of strings alphabetically
(ii) To print whether each word is palindrome or not
(iii) To count the length of the string
16. What are constants? Explain various types of constants in C. (M/J’15)
17. Write a C program to solve(roots of) Quadratic Equation ((M/J’15) (M/J’14)
18. Write a C program to add two matrices. (M/J’15)
19. Write a C program to search a number in an array of elements. (M/J’15) (N/D’14) 20. Write a C
program to arrange the given 10 numbers in ascending order/ Write a C program to sort array of
numbers. (N/D’14) (M/J’15) (M/J’14)
21. Explain various string handling functions in C. (M/J’15)
22. Explain various string operations. Write a C program to find the length of the string without using
build in function. (N/D’14)
23. Write a short notes on (i) #include<stdio.h> (ii) ifdef.. # endif (N/D’14)
24. Write a C program to check the given number is prime or not (M/J’14)
25. Write a C program to find sum of digits of a number (M/J’14)
26. Explain entry and exit checked conditional structure with example(M/J’14) 27. Write
a C program to subtract two matrices and display the resultant matrix.(M/J’14) 28.
(M/J’14)
***************
59