1 Knreddy: Programming in C & Data Structures
1 Knreddy: Programming in C & Data Structures
(ii) If the condition is true, it (ii) Executes the statements within the
executes while block if the condition is true.
some statements.
(iii) If the condition is false then it (iii) If the condition is false the control is
stops the execution the statements. transferred to the next statement of the loop.
13. What is the difference between while loop and do…while loop?
In the while loop the condition is first executed. If the condition is true then it executes the body
of the loop. When the condition is false it comes of the loop. In the do…while loop first the
statement is executed and then the condition is checked. The do…while loop will execute at
least one time even though the condition is false at the very first time.
15. How many bytes are occupied by the int, char, float, long int and double?
int - 2 Bytes char - 1 Byte float - 4 Bytes long int - 4 Bytes double - 8 Bytes
22. What will happen when you access the array more than its dimension?
When you access the array more than its dimensions some garbage value is stored in the array.
23. Write the limitations of getchar( ) and sacnf( ) functions for reading strings
getchar( ) To read a single character from stdin, then getchar() is the appropriate.
scanf( ) scanf( ) allows to read more than just a single character at a time.
31. What is the output of the following program when, the name given with spaces?
main( )
{
char name[50]; printf(“\n name\n”); scanf(“%s, name); printf(“%s”,name);
}
Output: knreddy (if i/p is knreddy cpds notes ) (It only accepts the data upto the spaces)
33. Why we don’t use the symbol ‘&’ symbol, while reading a String through scanf()?
The ‘&’ is not used in scanf() while reading string, because the character variable itself
specifies as a base address.
Example: name, &name[0] both the declarations are same.
34. What is the difference between static and auto storage classes?
Static Auto
Storage Memory Memory
Initial Zero Garbage value
value Local to the block in which the Local to the block in which
Scope variables is defined the variable is defined.
Value of the variable persists The block in which the
Life between different function variable is defined.
calls.
37. List out some of the rules used for ‘C’ programming.
All statements should be written in lower case letters. Upper case letters are only for symbolic
constants.
Blank spaces may be inserted between the words. This improves the readability of statements.
It is a free-form language; we can write statements anywhere between ‘{‘ and ‘}’.
a = b + c;
d = b*c;
Opening and closing braces should be balanced.
The condition is checked at the starting of The condition is checked at the end of the loop
the loop
Character constants are automatically converted Character constants are automatically converted
to integers. to integers.
In switch( ) case statement nested if can be used. In nested if statement switch case can be used.
Equivalent x = x + 1 Equivalent x = x - 1
47. Write a program to swap the values of two variables (without temporary variable).
#include <stdio.h>
#include <conio.h>
void main( )
{
int a =5; b = 10;
clrscr( );
prinf(“Before swapping a = %d b = %d “, a , b);
a = a + b;
b = a – b;
a = a – b;
prinf(“After swapping a = %d b = %d”, a,b);
getch( );
}
Output:
Before swapping a = 5 b = 10 After swapping a = 10 b = 5
55. How can you return more than one value from a function?
A Function returns only one value. By using pointer we can return more than one value.
59. What are the steps involved in program development life cycle?
Requirements
Analysis
Design
Coding/Implementation
Program Testing & Debugging
69. What is the deference between declaring a variable and defining a variable?
Declaring a variable means describing its type to the compiler but not allocating any space for
it.
Defining a variable means declaring it and also allocating space to hold the variable.
A variable can also be initialized at the time it is defined. To put it simply, a declaration says to the
compiler,
“Some where in the program there will be a variable with this name, and this is the kind of data
type it is.” On the other hand, a definition says, “Right here is this variable with this name and
this data type”. Note that a variable can be declared any number of times, but it must be defied
exactly once. For this reason, definitions do not belong in header files, where they might get
#included into more than one place in a program.
Array Pointer
1.Array allocates space automatically. 1.Pointer is explicitly assigned to point to an allocated space.
4.Size of(array name) gives the number 4.Sezeof(pointer name) returns the number of bytes used to
of bytes occupied by the array. store the pointer variable.
Arrays Structures
Arrays can only be declared. There is no Structures can be declared and defined. The deyword
keyword for arrays. for structures is struct.
An array name represents the address of A structrure name is known as tag. It is a shorthand
the starting element. notation of the declaration.
An array cannot have bit fields. A structure may contain bit fields.
Structure Union
Every member has its own memory. All members use the same memory.
The keyword used is struct. The keyword used is union. Different interpretations
for the same memory location are possible.
All members occupy separate memory
location, hence different interpretations of Conservation of memory is possible.
the same memory location are not possible.
Consumes more space compared to union.
C O L L E G E \0
Library functions are pre-defined set of The User-defined functions are the functions defined
functions that are defined in C libraries. by the user according to his/her requirement.
User can only use the function but cannot User can use this type of function. User can also
change (or) modify this function. modify this function.
In call by value, the value of actual agruments is In call by reference, the address of actual
passed to the formal arguments and the operation is argurment values is passed to formal argument
done on formal arguments. values.
Formal arguments values are photocopies of actual Formal arguments values are pointers to the actual
arguments values. argument values.
Changes made in formal arguments valued do not Since Address is passed, the changes made in the
affect the actual arguments values. both arguments values are permanent.