Wednesday, 27 August 2014

What would be the output of the following following Program?



#include<stdio.h>
#include<conio.h>
void main( )
{
               int a[ ] = {1,2,3,4,5};
               printf("%u,%u,%u",&a,a,&a[0]);
}

Options:

A)65516,65518,65560
B)65516,65516,1
C)65516,1,1
D)65516,65516,65516



Answer Option D)
-->for example the base address of the array a is 65516.
-->a, &a are points to the base address of the array and &a[0] is points to the address of first element in the array i.e base address.
So, answer is 65516,65516,65516.




Tuesday, 26 August 2014

What is the Output of the following Program?



#include<stdio.h>
#include<conio.h>
void main( )
{
            int x=10;
            int y=11;
            printf("%x,%d,%i,%x",x,x,x,y);
}

Options:
A)%x,10,10,%x
B)10,10,10,11
C)%x,10,%i,%x
D)a,10,10,b


Answer Option D)
-->%d and %i are used for integer datatype.
-->%x is used for hexadecimal notaion.
Number ---> HexaDecimal Value
   1        --->          1
   2        --->          2
   3        --->          3
   4        --->          4
   5        --->          5
   6        --->          6
   7        --->          7
   8        --->          8
   9        --->          9
   10      --->          a
   11      --->          b
   12      --->          c
   13      --->          d
   14      --->          e
   15      --->          f




Thursday, 21 August 2014

What would be the output of the following Program?



#include<stdio.h>
#include<conio.h>
void main( )
{
           int i;
           i = 999;
           if(i = 5)
           {
                    printf("You are Good");
           }
           else
           {
                    printf("You are Perfect");
           }
}

Options:
A)You are Perfect
B)You are Good
C)an error
D)none


Answer Option B)
Because i=5 is true statement
The purpose of the if statement is , if the condition is true then if block executed. Otherwise else block executed.




Wednesday, 20 August 2014

C Program for the following Statement



Statement:

                              Harish's basic salary is input through the keyboard. His dearness allowance  is 40% of basic salary, and house rent allowance is 20% of basic salary. write a program to calculate gross salary.


Program:

#include<stdio.h>
#include<conio.h>
void main( )
{
int s,da,hra,gs;
clrscr( ); // Clear the screen contents
printf("\nEnter the Basic Salary:");
scanf("%d",&s);
da=(s*40)/100;
hra=(s*20)/100;
gs=s+da+hra;
printf("\nDearness Allowance %d",da);
printf("\nHouse rent allowance %d",hra);
printf("\nGross Salary is %d",gs);
}



What is the output of the following Program?




#include<stdio.h>
#include<conio.h>
void main( )
{
            char far *p1, *p2;
            printf("%d,%d",sizeof(p1),sizeof(p2));
}

Options:
A)4,2
B)2,2
C)4,4
D) an error





Answer Option A)

-->A Pointer size is 2 bytes (for 16-bit compiler)
-->The size of far pointer is 4 bytes
-->The size of the huge pointer is 4 bytes
-->the far pointer is 16-bit segment value
-->the huge pointr is 16-bit offset value






Tuesday, 19 August 2014

What are the different Storage Classes in C language


Storage Classes:

                   Storage Classes specify the characteristic properties of the memory location where memory is allocated for that variable.

--> C Language Provide four types of storage classes as follows.
1) Auto Storage Class
2) Static Storage Class
3) Extern Storage Class
4) Register Storage Class

1)Auto Storage Class:

--> Here memory is allocated and de-allocated automatically based on scope of the variable.
--> When the control enters to the scope, memory is allocated.
--> When the control runs out of the scope, memory is de-allocated automatically.
--> So, scope of an automatic variable will be only for the block in which it is contained and it's time will be only for the execution of that block/function.

                                       Keyword:  auto

--> When we don't specify any storage class, then by default is auto

2)Static Storage Class:

--> It is useful when we are required to retain the values of variables even after coming out of the function.
--> for the static variables, memory is allocated only once when the program starts the execution and will be de-allocated when execution of the program is complete. 
--> So, scope of a static variable will be only for the function in which it is contained, where as life time will be throughout the execution of the program.

                                     Keyword : static

--> static variable assume a value of  "0"(zero) by default, we can also assign our interested value as required.

3)Extern Storage Class:

--> This is useful when different files in a project are required share/access a common variable.

                                    Keyword: extern

--> Only global variables can be declared as extern variables.

4)Register Storage Class:

--> It is useful when we are required to store the variable specified in a CPU register.

                                      Keyword: register






What is the Output of the following Program





#include<stdio.h>
#include<conio.h>
void main( )
{
            int i=10;
            printf("%d,%i",i,i);
}

Options:

A) 10, 20         
B) 10, 0
C) 10, 10
D) an error



Answer Option C)
Because we can give % i also for interger datatype




Introduction to C Language



Introduction:

                          A language represents set of symbols along with the rules to be followed while using these symbols.
                                                Language = Symbols + Rules

--> The rules are referred as "SYNTAX".
-->A Program represents set of sequence of instructions (or) commands (or) Statements which perform a pre-defined task.
--> A computer can understand only 0's(zero) and 1's(one). So, any symbol what we store in a computer should be converted ti 0's and 1's.
--> But it is not possible to convert a symbol directly to 0's and 1's. So, each and every symbol is given a unique identification, which is a number and is referred as "ASCII"(American Standard Code for Information Interchange) value.
--> All together we have 256 Symbols and so, 256 ASCII values ranging from 0,1,2,-------255.

ASCII Values for A-Z:

A - 65
B - 66
C - 67
D - 68
E - 69
F - 70
G - 71
H - 72
I - 73
J - 74
K - 75
L - 76
M - 77
N - 78
O - 79
P - 80
Q - 81
R - 82
S - 83
T - 84
U - 85
V - 86
W - 87
X - 88
Y - 89
Z - 90

ASCII values for a-z:

a - 97
b - 98
c - 99
d - 100
e - 101
f - 102
g - 103
h - 104
i - 105
j - 106
k - 107
l - 108
m - 109
n - 110
o - 111
p - 112
q - 113
r - 114
s - 115
t - 116
u - 117
v - 118
w - 119
x - 120
y - 121
z - 122

ASCII for for 0-9:

0 - 48
1 - 49
2 - 50
3 - 51
4 - 52
5 - 53
6 - 54
7 - 55
8 - 56
9 - 57