Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Programming With C

Uploaded by

Santanu Debnath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Programming With C

Uploaded by

Santanu Debnath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

COMPUTER SCIENCE PRANAB SAHA(B.

Sc(H), MCA)  9088134887

PROGRAMMING WITH C

1) What is keywords in C language?


Ans. – C language has its own set of reserved words that are used to construct a C program is called Keywords.
C language supports 32 kewords as follows :-
Auto Break Case Char Const Continue Default Do
Double Else Enum Extern Float Far For Goto
If Int Long Near Register Return Short Signed
Static Struct Switch Unsigned Union Typedef Void While
2) What is identifiers in C language?
Ans. – Identifiers are names that are used to identify the diff. parts of a program. These names can be given to things like
variables,constants,functions,arrays etc.
3) Rules for naming an identifiers ?
Ans. – i) It cannot be any keyword or reserved word.
ii) It can contain all the upper & lower case alphabets & the underscore(_) character.
iii) It can contain all the digits from 0 to 9 but cannot start with a digit.
iv) It cannot conatin a blank space.
[ NOTE – identifires are case sensitive i.e NAME & name are diff. identifiers in C].
4) What is Literals in C language ?
Ans. – A program may contain some fixed values which are used as part of the data processing. These values can be both
numeric like value of pi=3.14 & alphaneumeric like “Pranab”. Such values that do not change in a program & remains
same is called Literals or Constant values.
5) What is Operators in C language?
Ans. - Special symbols or combination of symbols are used in a C program to do specific operations like addition,
comparing values, incrementing a no. These symbols are called operators.
Ex. - &, +,-,*,/,%,=,>,<,>=,<=,==,!=,&&,|| etc.
6) What is punctuators in C language ?
Ans. – Special symbols are used in a C program as punctuations we use in English language. These are called punctuators.
Ex- (),{},[],;,:, ,
7) What is Instruction? What are diff. types of instruction in C language?
Ans. Meaningful components together forms an Instruction , which when run properly can solve a particular problem.
There are 4 basic types of instruction in C language.
i) Type declaration instructions : - example – int x,y=0;
ii) Input Output instructions :- example – scanf(“%d”,&x); printf(“The value is %d”,x);
iii) Arithmetic instruction : - example – 2*pi*r;
iv) Control instructions :- if(a%2==0) printf(“Even No.”); else printf(“Odd No.”);
8) What is function in C language ?
Ans. A function is a group of statements that performs some meaningful & specific work and normally returns a result
back to the point from where it was used.
Ex. – printf(), scanf(), main() etc.
9) What is the use of comment in C language?
Ans. For a better understanding of the program logic, sometimes it may be helpful to add comments in a program. The
program name, purpose of the program , version & any other related information may be include in a program. Such
information which is not a part of the program coding is knwon as Comment.
Comments are of 3 types :-
i) Single line comment.
ii) Multiline comment.
iii) Multiline documentation.
Example of single line comment : //printf(“This is our 1st C program”);
Example of Multiline comment:
/* Int a=5;
printf(“The No. is %d”); */
multiline comment will start with /* & end with */.
10) What is Pre processor directive ?
Ans. The standard libary provides several pre-written library functions, data type declaration that can be used in our
program. To use these utilities certain specific information needs to be included through include keywords. The header
file contains all the information that the compiler needs for functions dealing with input and output operations & working
with the disk, monitor & printer.
11) Describe diff. types of data type with size of each data type.
Ans.
NAME OF THE DATA SIZE OR RANGE Specifier Bytes
TYPE
Unsigned int 0 to + 65535 %d 2
Signed int -32768 to + 32767 %d 2
Unsigned long int 0 to + 4,294,967,295 %lu 4
Signed long int -2,147,483,648 to + 2,147.483.647 %lu 4
Unsigned char 0 to 255 %c 1
Signed char -128 to + 127 %c 1
Signed Float -3.4e-38 to + 3.4e38 %f 4
Double -1.7e308 to +1.7e308 %lf 8
Long double -1.7e4932 to + 1.7e4932 %Lf 10
String NA %s NA

Page no. -1
COMPUTER SCIENCE PRANAB SAHA(B.Sc(H), MCA)  9088134887

12) What is escape sequence? Discuss all the escape sequence in details?
Ans.Escape sequences are used to control the way the cursor moves on the screen or insert/display some special
characters.
Escape sequence Use
\n New Line
\t Tab space
\b Back space
\r move the cursor move the cursor to the beginning of
the same line
\f Eject the current page when output is sent to the
printer.

13) What is the utility of putchar() & puts() in C language?


Ans. putchar() – putchar() function displays a single character value on the screen. The parameter of the putchar() function
must be either a char literal , char constant or char variable.
puts() – puts() function displays a text string on the screen. It also displays unformatted string starting from a new line.

14) What is the utility of getchar() & gets() in C language?


Ans. – getchar() – getchar() to input any unformatted character data.One can input character either as a char or an int type.
gets()- gets() is used to input any type of unformatted text/string into a variable.The gets()function can be used to input any
type of string data.
15) What is the difference between putchar() & printf()?
Ans.
Putchar() Printf()
1) Is used to print a single character or integer 1) Is used to print any integer,character,float or string
value. values.
2) Is useful to print any single character. 2) Is useful to print any values.
3) ex.- char a=’x’; 3) ex. – char a=’x’;
putchar(a); int b=20;
printf(“%c %d”,a,b);
16) What is the difference between puts() & printf()?
Ans.
Puts() Printf()
1) Is used to print multiple character or string 1) Is used to print any integer,character,float or string
values only. values.
2) Is useful to print specific string only. 2) Is useful to print any values.
3) ex.- char a[20]; 3) ex- char a[20];
printf(“Enter your name”); int b=50;
gets(a); printf(“Enter your name”);
puts(a); gets(a);
printf(“%s %d”,a,b);
17) What is the difference between gets() & scanf()?
Ans.
Gets() Scanf()
1) Is used to take input multiple character or 1) Is used to take any integer,character,float or string
string values only. values as input.
2) Is useful to take input of specific string only. 2) Is useful to take input of any values.
3) ex.- char a[20]; 3) ex- char a[20];
printf(“Enter your name”); printf(“Enter your name”);
gets(a); scanf(“%s”,a);
18) What is the difference between getchar() & scanf()?
Getchar() Scanf()
1) Is used to take input single character only. 1) Is used to take any integer,character,float or string
values as input.
2) Is useful to take input of specific single character 2) Is useful to take input of any values.
only.
3) ex.- char a; 3) ex- char a;
printf(“Enter your name”); printf(“Enter your name”);
getchar(a); scanf(“%c”,a);
19) What is relational Operators in C? Mention the relational operators in C?
Ans. – C language provides us some special operators. These special operators allow us to compare 2 values to take a
decision. This is called relational operators.
Example - < , <= , > , >= , == , !=.
20) What is logical Operators in C? Mention the logical operators in C?
Ans. – When more than one condition needs to be tested to comes out at a decision we are taking help of logical operators.
Example - &&(AND), ||(OR), !(NOT).
21) What is conditional Operator or Ternary Operator in C? Explain with example.
Ans. Conditional operator is similar to that of an if-else statement, but with certain limitations. It is also known as ternary
Operatow with 3 argument.
General Syntax – exp1 ? exp2 :exp3
Example – int a=55,b=45;(a>b) ? (a) : (b);
22) What is unary operators? Give an example.
Page no. -2
COMPUTER SCIENCE PRANAB SAHA(B.Sc(H), MCA)  9088134887

Ans. When an single operand or variable is needed to work any operation these operators are called unary operators.
Ex. - ++(increment operator), --(decrement operator), +=(increment operator), -=(decrement operator), *=(multiplication
operator), /=(divisional operator), %=(modulus operator).
Suppose , int a=5;
a++ or a+=1 ; //is incremented i’s value by 1.
23) What is pre increment & post increment in C?
Ans. When an unary operator is placed before a variable or operand then it is called pre increment.
Ex. – int x=1;
Printf(“%d”,x);
++x;
Printf(“%d”,x);
Output will be 2 using pre increment operator.
When an unary operator is placed after a variable or operand then it is called post increment.
Ex. – int x=1;
Printf(“%d”,x);
x++;
Printf(“%d”,x);
Output will be 2 using post increment operator.
[ Note :in the same manner pre decrement & post decrement operators are used in C].
24) What is the difference between (While loop & For loop )with Do While loop.
Ans.
For / While Loop Do While Loop
1) they are called Entry controlled loop. 1) It os called Exit called loop.
2) Here if the condition is not satisfied then loop will 2) Here atleast once loop will execute because after
not entered into the loop & exit automatically. execution of loop 1 time the condition will check.
3) If the condition is not satisfied then the loop will not 3) Here the loop will execute atleast once.
execute once.
4)Ex. – 4) Ex.-
int i; int i=1;
for(i=1;i<=0;i++) do
{ {
Printf(“%d\n”,n); Printf(“%d\n”,i);
} }while(i<=0);
Loop will not execute as the condition is dissatisfied. Loop will execute atleast once as there is no
condition as the entry point of the loop.
25) What is continue statement in C? Discuss with example.

Ans. The continue statement is used to take the control to the beginning of the loop, bypassing certain statements within
the body of the loop. To use continue statement there should be an if statement which will check the condition.
Ex. - // WAP to print odd no. within a given range.
#include<stdio.h>
#include<conio.h>
void main()
{
int ctr=1,i=1;n;
printf(“Enter the Range”); scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
{
Continue;
}
Printf(“%d”,i);
}
getch();
}
26) What is the difference between break & continue statement?
Ans.
Break Continue
1) is used to forcefully come out of the loop or switch 1) is used to take the control to the beginning of the
case or program by bypassing the normal condition loop, bypassing certain statements within the body the
test or terminate a case in switch statement. loop.
2) break statement can be used in both switch case & 2) continue statement can be used in loop statement
loop statement. only.
3) It is used to goes out of the loop or switch. 3) It is used to continue the loop , by skipping some
portion of the loop.

Page no. -3
COMPUTER SCIENCE PRANAB SAHA(B.Sc(H), MCA)  9088134887

27) What is the diff. between for loop and while loop?

Ans. –

While loop For loop


1) while statement is usually used to perform an 1) for loop is usually used to perform an operation a
operation for an unknown number of times. fixed number of times.
2) The condition portion of the ‘while’ statement 2) The condition portion of the ‘for’ statement
contains only the conditions to be satisfied. contains initialization, condition & increment or
decrement.
3) Syntax- 3) Syntax-
while(condition) for(initialization;condition;increment or decrement)
{ {
Statements; Statements;
} }

Page no. -4

You might also like