Sei sulla pagina 1di 27

4.

1 C FUNDAMENTALS

4.1.1 PROGRAMMING
Q.1) What is a computer program?
Ans: Computer program is a collection of instructions which are necessary to solve a specific
problem.

Q.2) What is an algorithm?
Ans: The step by step procedure which is used to solve the problem is known as algorithm.

Q.3) Give an example for alghorithm?
Ans: step0:start
step1:read a number
srep2:if number%2 is zero then print number is even
step3.else print number is odd.
step4:end

4.1.2 HIGH LEVEL LANGUAGES
Q) What is high level language?
Ans: A language which is easy to read and understand by the programmer.

Q.4) Give an example of low level languages?
Ans: Assembly level language is an example of low level languages.

Q.5) Give an example of high level languages?
Ans: Fortran, C is an example of high level languages.

Q.6) Give an example of operating system?
Ans: Microsoft Windows XP,LINUX.

4.1.3 COMPILING PROGRAMS

Q.7) What is a compiler?
Ans: Compiler is a software program which translates high level program in to machine level.

Q.8) What is the function of assembler?
Ans: Assembler translates each assembly language statement and converts it into machine code
format known as object code.

Q.9) What is meant by building a program?
Ans: The process of compiling and linking a program is often called building a program.
4.1.4 INTEGRATED DEVELOPMENT ENVIRONMENT(IDE)

Q.10) What is integrated development environment?
Ans: The process of editing, compiling, linking ,debugging and executing programs is known as an
IDE.

Q.11) Give an example of IDE under ms dos?
Ans: Under windows tc is a good example of popular IDE.

Q.12) Give an example of IDE under linux?
Ans: KYLIX is a popular IDE for developing applications under LINUX.

Q.13) Give an example of IDE under Mac OS X?
Ans: Code Warrior and Xcode are two IDE's that are used by pragrammers.

Q14) What is an interpreter?
Ans: An interpreter is a software which translates machine code line by line. debugged.

Q.15) What is a comment?
Ans: A comment serves to tell the reader just what the reader had in mind when he/she wrote a
particular program.

Q.16) How to write a comment in C?
Ans: /*any thing in between this is treated as comment*/

Q.17) How to compile a program?
Ans: $ gcc filename.c or cc file name.c
if you are using unix C compiler the command is 'cc' instead of 'gcc'.

Q.18) How to assign a different name for executable file?
Ans:"- o"(that's the letter O) which is followed by the name of the executable file.
example: gcc filename.c -o executable file name

Q.19) Write a simple program that prints 'HELLO WORLD'?
Ans: #include<stdio.h>
void main()
{
printf("HELLO WORLD");
}

Q.20) How to terminate statements in C?
Ans: All program statements in C must be terminated by semicolon(;).

CHAPTER 4.2
VARIABLES, DATA TYPES, ARITHMETIC EXPRESSIONS, INPUT & OUTPUT
FUNCTIONS

DEFINITIONS
4.2.1 INPUT FUNCTIONS:
scanf: It is a function used to read values entered by the user upon execution of a program.

4.2.2 OUTPUT FUNCTIONS:
printf: It is a function used to print and display output of a program


4.2.3 WORKING WITH VARIABLES
C Tokens:In a passage of text individual words and punctuation marks are called tokens.

VARIABLE: A VARIABLE IS A DATA NAME THAT MAY BE USED TO STORE A DATA
VALUE

4.2.4 UNDERSTANDING DATA TYPES AND CONSTANTS
CONSTANTS: Constants is a fixed values that do not change during the execution of a program.

DATA TYPES: Te variety of data types available allow the programmer to select the type appropriate
to trhe needs of the application as well as the machine.

4.2.5 WORKING WITH ARITHMETIC EXPRESSION:
ARITHMETIC OPERATORS: +,-,*and / ,% .

What are different inbuilt data types available in c?
int, char, float, long, double.


ONE WORD ANSWERS
4.2.1 INPUT FUNCTIONS:
4.2.2 OUTPUT FUNCTIONS:
4.2.3 WORKING WITH VARIABLES:

Q1) What are the rules for variables ?
Ans: 1. They must begin with a letter, or with underscore.
2. ANSI standard recognises a length of 31 characters.
3. Upper case and lower case letters are significant.
4. Cannot use a keyword.
5. Must not contain white space.
6. It can have digits at middle or end.

Q2) Give examples for valid variable names?
Ans: John value, T_raise, delhi, x1, ph_value, mark, sum1, distance

Q3) Is char a valid variable name?
Ans: NO, char is a keyword

Q4) Is price$ a valid variable name?
Ans: NOT VALID dollar sign is illegal.

Q5) Is 'group one' a valid variable name?
Ans: NOT VALID blank space not permitted.

Q6) Is int_type a valid variable name?
Ans: valid, keyword may be a part of a name.


4.2.4 UNDERSTANDING DATA TYPES AND CONSTANTS:

Q7) What are the data types that ansi c support?
ANS: ANSI c supports three classes of data types .they are
1. Primary (or fundamental)data type
2. Derived data types
3. User defined data types

Q8) What is the size and range of the basic data types?
Ans: The size and range of the basic data types is
Datatype size (bytes) range
int 2 -32,768to +32767
char 1 -128 to +127
float 4 3.4e-38 to 3.4e+38
double 8 1.7e-308to1.7e+308
Q9) What is the size and range of short int(or)signed short int,long int (or)signed long int?
Ans: DATA TYPE SIZE RANGE
Short Int (or) signed short int 2 -128 TO +127
Long Int (or) signed long int 4 -2^31,648TO 2^31-1

Q10) When is a function said to be void?
Ans: A function is said to be void when it does not return any value to the calling function.

Q11) How many types of character constants are there in c?
Ans: C has two types of constants. They are
1. Numeric constants
2. Character constants

Q12) How many types of numeric constants are there?
Ans: There are two types of numeric constants. They are:
1. Integer constants
2. Real constants

Q13) How many types of character constants are there?
Ans: There are two types of character constants. They are:
1. Single character constants
2. String constants

Q14) How many types of integer are there?
Ans: There are three types of integers namely, decimal, octal, hexa decimal integer

Q15) Is embedded spaces, commas and non digit characters are permitted between decimal integer
constants?
Ans: NO, embedded spaces, commas and non digit characters are NOT permitted between decimal
integer constants.

Q16) Is '20,000' a valid decimal integer constant?
Ans: Not valid

Q17) Is '$1000' a valid decimal integer constant?
Ans: NOT VALID

Q18) Give an example of octal integer constant?
ANS: 037
0435
0551


Q19) Give an example of hexa decimal integer constant?
Ans: 0x2
0x9f
0xbcd
ox

Q20) Give an example of real type constant?
Ans: 0.0083,-.75,435.36,+247.008

Q21) Give an example of single character type constant?
Ans: '5','x',';'

Q22) What will be the output when the statement gets executed?
printf ("%d", 'a');
Ans: the statement when executed the output will be 97 which is ASCII value of the letter a.

Q23) What will be the output when the statement gets executed?
printf ("%c", 97);
Ans: The statement when executed the output will be a.

Q24) What does the symbol '\n' stands for?
Ans: The symbol stands for new line character.

Q25) Give examples of valid string constants?
Ans: Examples of some valid string constants are
"hello"
"1987"
"well done"
"5+3"
"x"

4.2.5 WORKING WITH ARITHMETIC EXPRESSION:
Q26) What is real arithmetic?
Ans: An arithmetic operation involving only real operand is called real arithmetic.

Q27) What is an integer expression?
Ans: When both the operands in an expression are integers then the expression is called an integer
expression.

Q28) Let a=14, b=4 what will be the output for the following
a) a-b b) a+b c) a*b d) a/b e) a%b
Ans: a) 10
b) 18
c) 56
d) 3
e) 2

Q29) When is an expression called mixed mode arithmetic?
Ans: When one of the operands is real and the other is integer, the expression is called mixed mode
arithmetic.

Q30) What will be the value of c for float c=15/10.0& int d=15/10, float e = 15/10 and float
f= 15/10.0?
Ans: c = 1.5
d = 1
e = 1.0
f = 1.5

CHAPTER 4.3 OPERATIONS IN C:
4.3.1 Arithmetic operators:
Q1) How many arithmetic operators are there ?
Ans: Five

Q2) What are the different arithmetic operators?
Ans: The different arithmetic operators are:
+ (addition), -(subtraction), *(multiplication), /(division),
% (modulo division).

Q3) What is precedence of operators?
Ans: Precedence of operators decides the order in which different operators are applied.

Q4) What is associativity ?
Ans: Associativity decides the order in which multiple occurrences of the same level operator are
applied.

Q5) Which arithmetic operator has highest precedence?
Ans: */%

Q6) Which arithmetic operator has lowest precedence?
Ans: + -

Q7) What is the associativity of arithmetic operators?
Ans: left to right

Q8) Which operator has highest precedence level in c?
Ans: ()[] has highest precedence level in c language.

Q9) What will be the value of x,y,z for a=9,b=12,c=3(all are declared as float data type)
1. x = a-b/3+c*2-1;
2. y = a-b/(3+c)*(2-1);
3. z = a-(b/(3+c)*2)-1;
ans: x = 10.0000
y = 7.0000
z = 4.0000
4.3.2 RELATIONAL OPERATORS:
Q10) How many relational operators are there?
Ans: Six

Q11) What are the different relational operators?
Ans: The different relational operators are:
<(is less than), <= (less than or equal to), > (greater than),
>= (greater than or equal to), == (equal to), !=(not equal to)

Q12) Which relational operators have highest precedence?
Ans: >, <, >=, <=

Q13) Which relational operator has lowest precedence?
Ans: ==, !=

Q14) What is the associativity of relational operators?
Ans: Left to right

Q15) Which have highest priority level in arithmetic and relational operators both are used?
Ans: Arithmetic operators


4.3.3 ASSIGNMENT OPERATORS:
Q16) What are the different assignment operators?
Ans: =, *=, /=, %=, +=, -=, &=, ^=, |=, <<=, >>==

Q17) What is the associativity of assignment operators?
Ans: Right to left

Q18) Does the expressions x+= y+1, x=x+(y+1) are same?
ans: Yes both are same

Q19) What will be the values of a, b, c, d (all are integer data types) and initially a=10,b=3,c=2,d=8
1. a+=1;
2. b-=1;
3. c*=2;
4. d/=4;
Ans: a=11, b=2, c=8, d=2.





4.3.4 LOGICAL OPERATORS:
Q20) How many logical operators are there?
Ans: Three

Q21) What are the different logical operators?
Ans: && (LOGICAL AND), || (LOGICAL OR), !(LOGICAL NOT)

Q22) What is the associativity of logical and (&&), logical or (||) ?
Ans: Left to right

Q23) What is the associativity of logical not ?
Ans: right to left

4.3.5 INCREMENT AND DECREMENT OPERATORS:
Q24) What is the associativity of increment and decrement operators?
Ans: right to left

Q25) What is an increment operators?
Ans: ++

Q26) What is a pre increment ?
Ans: ++a

Q27) What is post increment?
Ans: a++

Q28) What is decrement operator?
Ans: --

Q29) What is pre decrement ?
Ans: --a

Q30) What is post decrement?
Ans: a--

Q31) What is the value of m and y in the below expression?
m = 5;
y = ++m;
Ans: m=6,y=6

Q32) What is the value of m and y in the below expression?
m = 5;
y = m++;
Ans: y=5, m=6

4.3.6 CONDITIONAL OPERATOR:

Q33) What is conditional operator?
Ans: a ternary operator pair(? :)

Q34) What is the associativity of conditional operator?
Ans: right to left

Q35) What will be the value of x after evaluating the following expression?
a=10; b=15; x= (a>b)?a:b;
Ans: 15

4.3.7 BITWISE OPERATORS:
Q36) How many bitwise operators are there?
Ans: FIVE

Q37) What are the different bit wise operators?
ans: Bit wise AND(&), bit wise OR(|), bit wise exclusive OR(^),
shift left(<<), shift right (>>), are called bit wise operators

Q38) What is the associativity of bitwise operators?
Ans: left to right

CHAPTER 4.4

Decision making and looping

4.4.1 The IF statement

The if statement is an decision making statement and used to control the flow of execution of
statements. It's general syntax is
if(test expression)
{
executable part;
}

1. When will be the executable part in the if statement is executed?
A: Only when the test expression is true.

2. what is the other name of if statements?
A: decission control statements.

4.4.2 THE IF ELSE construct
The if else statement is an extension of the simple if statement .It's general syntax is
if(test expression)
{
true block statements;
}
else
{
false block statements;
}
if the test expression is true,then the true block statements are executed otherwise the flase block
statements are executed.

3. When will be the else part be executed?
A: Only when ifs text expression is false.

4.4.3 NESTED IF STATEMENTS
When a series of decisions are involved we may have to use more than one if statements. Then
we use nested if statements. Its general syntax is
if(test condition 1)
{
if(test condition 2)
{
statements..
}
}
4. When will be the nested if be executed?
A: Nested ifs are executed only when all the testconditions are satisfied.

4.4.5 SWITCH STATEMENT
The switch statement test the value of a given variable against a list of case values. When a
match is found a block of statements associated with the case is executed its general syntax is
switch(expression)
{
case value-1:
block-1;
break;
case value-2:

block-2;
break;
....
default:
default -block;
break;
}

6. What is meant by the default statements?
A: When the entered value is not among the case values then default statements are executed.

7. Which type of data is allowed in switch case?
A: int or char constant.

4.4.7 The Conditional operator
The conditional operators ? and : are called as ternary operators since it has three arguments.
They form a kind of general foreshortened if-then-else their general form is
expression1?expression2:expression3

8. How many operands required for conditional operator?
A: 3.
Chapter 4.5 Looping statements
4.5.1 The FOR statement
The for loop is a entry controlled loop that provides a more concise loop control structure.
its general syntax is
for(initialization;test-condition;operator)
{
body of the loop;
}
4.5.2 NESTED FOR LOOPS

Nested for loops means one for loop within other for loop its general syntax is
for(initialization1;testcondition;operation)
{
for(inittialization2;testcondition2;operation)
{
...............
}
}

4.5.3 The while statement
it is the simplest of all looping structures in C.it is also an entry controlled statement.
its general syntax is
while(test condition)
{
body of loop;

}
4.5.4 The do statement
It is same as the while statement but the test condition is placed at the bottom of the loop.
its general syntax is

do
{
bodyof the loop;
}
while(test-condition);
Q) How many times a do while loop executes atleast?
Ans: 1 time.

4.5.5 The break and continue statements
When a break statement is encountered in a loop, the loop is immediately exited from the loop
and the program continues continues with the statement immediately following the loop.
while (test-condition)
{
if(-----------)
break;
---------
---------
}

when it is necessary to skip a part of the loop we use continue statements.
its general syntax is
while(test-condition)
{
if(-----------)
continue;
---------
---------
}
CHAPTER 4.6


WORKKING WITH ARRAYS
6.1 Defining an array
6.2 Declaration and Initializing the array
6.3 Character arrays
6.4 the const qualifier
6.5 Multidimensional array
6.6 Variable length arrays

ONE WORD ANSWERS

1. What is an array?
A: collection of homogeneous data is known as array.

2. how many types of arrays are there and what are they?
A: there are 3 types of arrays they are
a) one dimensional array
b) two dimensional array
c) multi dimensional array

3. what is an one dimensional array?
A: a list of items given in one variable name using only one subscript is known as one dimensional
array.
example:int a[3]

4. what is two dimensional array?
A: collection of homogeneous elements in rows and columns is known as 2-dimensional array.
example:int matrix[3][3]


5. what is the general format of declaring an array?
A: data type variable name[size]
note: the size must be an integer.

6. what is the value of starting index of an array?
A. zero

7. what is the use of const qualifier?
A. the compiler allows to associate the const qualifier with variables whose values will not be
changed by the program.

8. what value is automatically assigned to those array elements that are not explicitly initialized?
A: all of array elements automatically set to zero except those that have been explicitly initialized
with in array definitions.

9. State the rule that determines the order in which initial values
are assigned to multi dimensional array elements?
A. the rule is that the last (right most) subscript increases most
rapidly and the first (left most) increases least rapidly.

Chapter 4.7

4.7. WORKING WITH FUNCTIONS:
4.7.1 Defining a function.
4.7.2 Arguments and local variables.
4.7.3 returning function results.
4.7.4 Function calling.
4.7.5 declaring return types and argument types.
4.7.6 top down programming.
4.7.7 Functions and arrays.
4.7.8 global variables.
4.7.9 Automtic and static variables.
4.7.10 Recursive function






One word answers
4.7.1 DEFINING A FUNCTION:

1.What is a function?
A: a function is a self-contained block of code that performs a particular task,it is also called
module.

2. How many types of functions are there,what are they?
A: there are two types of functions they are
a.User-defined functions
b.standard library functions.

3. What are the advantages of using functions?
A: a. The length of the source program can be reduced by using function.
b.It is easy to locate and isolate a faulty functions for further investigations.

4.7.2 Arguments and local variables:

4. what is Function definition?
A: It is an independent program module that is especially written to implement the requirements of
the function.

5. What are the elements involved in function definition?
A: The six elements that are involved in a function definition are:
a.Function return type
b.Function name
c.Parameter list
d.Local variables
e.Function statements and
f.Return statement

6. What is function header?
A: The function type,function name and the parameter list together is called
a function header.

7. What is function body?
A: The local variables the function statements and the return statement on a whole is known as
function body.

8. What are formal parameters?
A: The parameter list declares the variables that will receive the data sent by the calling
programme. They serve as the input data to function to carry out the specified task since they
represent actual input values, they are called as the "formal parameters".

9. What are actual parameters?
A: The parameters which are used in the function call are called as actual parameters. These may be
simple constants, variables or expressions.

4.7.2 Arguments and local variables:

10. what is an ARGUMENTS?
A: This is one type of parameter which collects the value from the calling function.

11. what are LOCAL VARIABLES:
A: These are the variables which are declared inside the function.

4.7.4 FUNCTION CALLING:

12. What is function declaration?
A: The calling function should declare any function that is to be used later in the program this is
known as function declaration or function prototype.

13. what are types of function prototype?
A: There are two types of function prototypes. They are
a.global prototype
b.local prototype

14. what are the main elements required in the function prototype?
A: The main elements required in the function prototype are:
a.function return type
b.function name
c.parameters list
d.terminating semicolon

NOTE: Terminating semicolon(;) is important.


4.7.5 DECLARING RETURN TYPES AND ARGUMENTS:

15. What are the types of functions depending upon categories of arguments and return statements?
A: Depending upon categories of arguments and return statements there are four types of functions
a. function with no arguments and no return values
b. function with arguments and no return value
c. function with arguments and one return value
d. function with no arguments but return a value

16. How do you return multiple values to the calling function?
A: Multiple values to the calling function can be returned using "POINTERS".

17. How do you pass multiple variables using pointers?
A: Multiple values can be passed using pointers by using addresses of variables in the actual
parameters.

4.7.7 FUNCTIONS AND ARRAYS:

18. What are the rules to pass an array to a function?
A: The rules are:
a.the function must be called by passing only the name of an array
b.the function definition, the formal parameter must be an array type; the size of an array does
not need to be specified.
c.the function prototype must show that the argument is an array.

19. Is it possible to pass an entire array to a function as an argument?
A: yes, it is possible to pass an entire array to a function as an argument.

20. How to pass an array to a function?
A: To pass an array to a function ,the name of the array must appear itself, without brackets or
subscripts, as an actual argument with in the function call.

4.7.9 Automtic and static variables :

21. What are automatic variables?
A: These are the variables declared inside a function in which they are utilised. They are cerated
when the function is 'called' and destroyed automatically when the function is exited.

22. What are static variables? what are its types?
A: These are the variables which persist until the end of the program. They are of two types
a.Internal static variables: are those declared inside a function.
b.External static variables: are those declared outside a function.

4.7.10 RECURSIVE FUNCTIONS:
23) What is a recursive function?
A: a function which calls itself is known as recusive function.

24) Give an example where we use recursion?
A: Recusion can be used for doing progrms like mathematical induction, fibbonaci series etc.....
CHPATER 5.1
WORKING WITH STRUCTURES

5.1.1 defining a structure:

STRUCTURE:
A structure is a user defined datatype and it is used for handling a group of logically related
datatypes.

5.1.3 INITIALISING STRUCTURES:
Structures can be intialised either at compiletime or at runtime.

1. What is a structure?
A: A structure is a collection of heterogeneous data.

2. How is a structure defined?
A: Structures must be defined first for their format that may be used later to declare structure
variables. The general format\layout of a structure is struct tag_name
{
datatype name1;
datatype name2;
:
:
:
};
where name1,name2......... are called as structure variables.

3. What are the major differences between arrays and structures?
A: a. an array is a collection of similar datatypes where as the stuctrure is a collection of different
data types.
b. an array is derived datatype where as a structure is user defined datatype.

5.1.3 INITIALISING STRUCTURES:
4. How the members of a structure are accessed?
A: The members of a structure are accessed using the dot operator or arrow operator.

5. How is the structure initialised at compiletime?
A: Structure at compiletime can be initialised in this way
struct tag_name
{
int a;
char c[10];
};
struct tag_name s1={10,"ravi"};

6. How is the structure initialised at runtime?
A: Structure at runtime can be initialised in this way
struct tag_name
{
int a;
char c[10];
};
struct tag_name s1;
scanf("%d,%c",&s1.a,s1.c);

7. What is called nested structure?
A: A structure within a structure is called as nesting of structure.

5.1.4 ARRAY OF STRUCTURES:

8 give an example of array of structures?
A: struct class student[100];

9. what is the general format of sending a copy of a structure to the called function?
A: the general fomrat of sending a copy of a structure to the called function is
function_name(structure_variable name);

10. how many levels C allows nesting of structures?
A: C permits nesting of structures upto 15 levels
CHAPTER 5.2
STRINGS AND CHARACTER ARRAYS


5.2.1 ARRAY OF CHARACTERS:

Q1. What is a string?
A. A string is a collection of ckharacters that is treated as single data type.

Q2. Write the general form of the declaration of a simple string?
A. char string_name[size];

Q. Other than the scanf function,what is the other function that can be used to read the character
string?
A. getc is the othere function that can be used to read the character string.

5.2.2 VARIABLE LENGTH CHARACTER STRINGS:

Q. what is the funtcion we use to write the string on the screen?
A. printf() function by using format code %s.

Q. what is meant by getchar()?
A. it print's the charector from the keyboard.

Q. what is meant by concatenation?
A. The process of combining one string with another is known as concatneation.

Q. what is meant by stringcopy?
A. The process of comparing the one string into another is known as string copy.

Q. what is the header file we use for string operations?
A. string.h .

Q. what is meant by strncpy?
A. this is a three parameter function that copies only the left n characters of the source string to the
target string.The general format of the function is
strncpy(s1,s2,n);
where s1=target string
s2=source string
n=left 'n' charectors of the source string.

Q. what is meant by strncmp?
A. This is a three parametre function that compares only 'n' characters in both the strings.
the general layout of the function is
strncmp(s1,s2,n); .
CHAPTER 5.3
POINTERS

Pointer:A pointer is a derived data type in C which is used to store the address of the variable.
1. what is a pointer?
A: A pointer is a derived data type in C which is used to store the address of the variable.

2. what are the advantages of the pointer?
A: a.pointer are more efficent in handling arrays and data tables.
b.pointers allow C to support dynamic memory allocation.
c.operations at memory level can be done efficiently.

3. what are pointer constants?
A: memory address with in a computer are reffered to as pointer constants.we cannot change
them.we can use them only to store values.

4. how the address of the varible can be accessed?
A: by using '&' operator.

5. how the pointer varible can be declared?
A: by using the syntax given below
data type *pt_name
where data type is - what type of data the varible is going to assigned
pt - means pointer

6. what is meant by initialization of pointers?
A: the process of assigning the address of varible to a pointer is known as initialization of pointer.

7. how can we access the value at the that pointer?
A: by using the deferncing operator asterik(*).

CHAIN OF POINTERS:
The process of linking the pointer varible to another pointer varible is known as chain of
pointers.this can be shown as **p.

8. what are pointer expressions?
A: the experssion is a squence of operators and operands.if the operands used here are pointers then
the expression becomes pointer expressions.

9. can the pointer increments are possible?
A: yes,they are possible.


10. what is scale factor?
A: when the pointer is incremented,its value is increased by the 'length of the data type'.this is
known as scale factor.

11. what the compiler does when the array has been assigned to pointer?
A: the compiler allocate the address of the first member of an array to pointer.

12. what is meant by call by value?
A: The process of passing th actual address of varibles to the function
is known as call by value.

13. which operator is used to access the structure member when we use pointer in structures?
A: arrow operator(->) or member selection operator.

14. what are the disadvantages of the pointer?
A: a.the compiler may not detect the error in the programm.
b.debugging becomes difficult task.
c.direct access of memory loose data security

15. which arithmetic operations are allowed in pointers?
ans: addition and subtraction.

16. what is a near pointer?
ans: a pointer which can store an address value between 0 to 65,535.
near pointer requires 2 bytes of memory.

17. what is a far pointer?
ans: a pointer which can store an address value between zer0 to 2 pow(32)-1.
far pointer requires four bytes of memory.

18. what is a genric pointer?
ans: a pointer which can store any type of address,it is represented by void *.
example: void *ptr.

19. what is wild pointer?
ans: a pointer which is not initialized by any addresss.

20. What is single pointer?
Ans: a single pointer stores address of a variable.
example: int *ptr,val;
val=54;
ptr=&val;


21. What is double pointer?
ans: a double pointer stores address of a single pointer.
example: int **p2,*p1,x;
p1=&x;
p2=&p1;
CHAPTER 5.4
OPERATIONS ON BITS


5.4.1.BIT OPERATORS

Q. What are bit-wise operators?
A. Bit wise AND(&),bit wise OR(|),bit wise exclusive OR(^),shift left(<<),shift right(>>) ,are
called bit operators.

THE PREPROCESSOR

5.5.1.THE #DEFINE STATEMENT

Q. What is #define directive?
A. a #define is a preprocessor compiler directive and not a statement.

Q. What is the use of #define statement?
A. The use of #define statement is to assign symbolic names to program constants it is used to
define a simple macro.

Q. Give some examples as how to use #define statement.
A. #define YES 1
#define NO 0

Q. Would #define lines end with a semicolon(;)?
A. NO,#define lines donot end with a semicolon(;)

5.5.2. THE ##OPERATOR

Q. Where do we use ## operator?
A. This operator is used in macro definitions to join two tokens together

5.5.3. THE #INCLUDE STATEMENT

Q. What are header files?
A. Library functions are grouped category wise and stored in different files known as 'header files'

Q. How to acess functions stored in the library?
A. Functions in the library can be accessed using the #include directive

5.5.4.CONDITION COMPILATION
Q. What is the function of #ifdef?
A. It is the test for a macro definition

Q. What is the function of #endif?
A. It specifies the end of #if

Q. What is the function of #if?
A. IT specifies alternatives when #if test fails

Q. What is the function of #ifndef?
A. It tests whether a macro is defined or not
5.6. MORE ON DATA TYPES
5.6.1. ENUMERATED DATA TYPES

Q) what is enum?
ans: it is a special keyword which allows to define symbolic constants.

Q. How is enum defined?
A. It is defined as follows enum identifier{value1,value2,..................valuen};

Q. Give examples for enumerated datatypes.
A. enum day {monday,tuesday..............sunday};
enum day week_st,week_end;

Q) what is the starting value of enumerated set?
ans: zero
5.6.2. THE typedef STATEMENT

Q) waht is typedef?
ans: it is used to redfine an existing data type.

Q. Give some examples how to use typedef?
A. typedef int units;
typedef float marks;
they can later be used to declare the variables as follows
units batch1,batch2;
marks name1[50],name2[50];
5.6.3.DATA TYPE CONVERSIONS

Q. Illustrate the use of data type conversion
A. average=(float) total/n;
the value of the variable total; is converted to type float before the operation is
performed,thereby guarantee that the division will be carried out as a floating point operation



CHAPTER 5.7
INPUT AND OUTPUT OPERATIONS in c

5.7.1. Character I/O:

Q. What are character I/O functions?
A. putchar and getchar are character I/O functions

Q. When do we use getchar?
A. getchar function is used when we want to read a single character at a time.

Q. What is the use of putchar?
A. It is used to display single character data type

5.7.2.FORMATTED I/O:

Q. What are formatted I/O functions?
A. scanf and printf are formatted I/O functions

5.7.3 INPUT AND OUTPUT OPERATIONS WITH FILES:
Q1) how many types files are categorised?what are they?
ans: two,they are:text file,binary file

Q2) what does a text file stores?
ans: a text file stores different characters such as:
upper case,lower case english alphabets,numeric characters,
punctuation characters,special characters.

Q3) how to create text files?
ans: text files are created by using .txt extension.

Q4) how to declare and open a file for writting?
ans: FILE *fp;
fp=fopen("file name","w");

Q5) how to declare and open a file for reading?
ans: FILE *fp;
fp=fopen("file name","r");
Q6) how to declare and open a file for appending?
ans: FILE *fp;
fp=fopen("file name","a");
Q7) how to close a file?
ans: fclose(file_pointer);

Q8) what are the simplest file i/o functions?
ans: getc,putc,fprintf,fscanf

Q9) what is the general form of getc?
ans: getc(fp);
reads a character from the file
whose file pointer is fp.

Q10) what is the general form of putc?
ans: putc(c,fp);
writes the character contained in the character variable c
to the file associated with FILE pointer fp.

Q11) what are the simplest file i/o integer functions?
ans: getw,putw.

Q12) what is the general form of fprintf?
ans: fpintf(fp,"control string",list);
example:fprintf(p1"%s %d %f ",name,age,7.5);

Q13) what is the general form of fscanf?
ans: fscanf(fp ,"control string",list);
example: fscanf(f1"%s %d",item,&quantity);

5.7.4 SPECIAL FUNCTIONS FOR WORKING WITH FILES:
Q14) how many types of status enquiry library functions are there?what are they?
ans: two.they are
1.feof
2.ferror
Q15) what is the use of status enquiry library functions?
ans: they help to detect i/o errors with in the files.

Q16) what is the use of ftell? write the general form of ftell?
ans: ftell function is useful in saving the current position of file .
it takes the general form:
n=ftell(fp)
it returns a number of type long.

Q17) what is the rewind function?
ans: rewind takes a file pointer and resets the position to the start of the file.
general form:rewind(fp);

Q18) where is fseek function used?
ans: fseek function is used to move the file position to a desired
location with in the file.

Q19) what is the general form of fseek function?
ans: fseek(file_ptr,offset,position);
offset specifies number of positions to be moved,position is 0(meaning
begining of file),1(current position),2(end of file).

Q20) what is the meaning of the following statement?
fseek(fp,m,1)
ans: go forward by m bytes.


CHAPTER 5.8
MISCELLANIOUS AND ADVANCED FUNCTIONS

5.8.1.THE GOTO STATEMENT

Q. What is the use of goto statement?
A. goto statement is used to branch unconditionally from one point to another in the program

Q. How to use goto label?
A. goto label;----
|
---------- |
---------- |
---------- |
label <-----


label; <----
statement |
---------- |
---------- |
---------- |
goto label-----

5.8.3 WORKING WITH UNIONS:

Q) what are unions?
ans: unions follow same syntax as strucures
but the major difference is in terms of storage.

Q) what is the size of the memory allocated by union?
ans: the compiler allocates a piece of storage that is
large enough to hold the largest variable type in the union.


5.8.4 THE COMMA OPERATOR:

Q) what is the use of comma operator?
ans: the comma operator can be used to link the related expression together.

Q) in which direction the comma-linked list of expressions are evaluated?
ans: left to right,the value of rightmost expression is the value of combined expression.

Q) give applications of comma operator?
ans: for loops,while loop.

Potrebbero piacerti anche