C interview questions and answers



C interview questions and answers for freshers. It is basic c language technical frequently asked interview questions and answers. It includes data structures, pointers interview questions and answers for experienced
Interview questions and answer of C with explanation for fresher

1
Write a c program to print Hello world without using any semicolon.
Answer
Explanation:
Solution: 1
void main(){
    if(printf("Hello world")){
    }
}

Solution: 2
void main(){
    while(!printf("Hello world")){
    }
}

Solution: 3
void main(){
    switch(printf("Hello world")){
    }
}

2
Swap two variables without using third variable.
Answer
Explanation:
#include<stdio.h>
int main(){
    int a=5,b=10;
//process one
    a=b+a;
    b=a-b;
    a=a-b;
    printf("a= %d  b=  %d",a,b);

//process two
    a=5;
    b=10;
    a=a+b-(b=a);
    printf("\na= %d  b=  %d",a,b);
//process three
    a=5;
    b=10;
    a=a^b;
    b=a^b;
    a=b^a;
    printf("\na= %d  b=  %d",a,b);
   
//process four
    a=5;
    b=10;
    a=b-~a-1;
    b=a+~b+1;
    a=a+~b+1;
    printf("\na= %d  b=  %d",a,b);
   
//process five
    a=5,
    b=10;
    a=b+a,b=a-b,a=a-b;
    printf("\na= %d  b=  %d",a,b);
    return 0;
}

3
What is dangling pointer in c? 
Answer
Explanation:
Dangling pointer:

If any pointer is pointing the memory address of any variable but after some variable has deleted from that memory location while pointer is still pointing such memory location. Such pointer is known as dangling pointer and this problem is known as dangling pointer problem.

Initially:

Later:
For example:

What will be output of following c program?

#include<stdio.h>

int *call();
int main(){

int *ptr;
ptr=call();

fflush(stdin);
printf("%d",*ptr);
return 0;
}
int * call(){

int x=25;
++x;

return &x;
}

Output: Garbage value
Note: In some compiler you may get warning message returning address of local variable or temporary

Explanation: variable x is local variable. Its scope and lifetime is within the function call hence after returning address of x variable x became dead and pointer is still pointing ptr is still pointing to that location.

Solution of this problem: 
Make the variable x is as static variable. In other word we can say a pointer whose pointing object has been deleted is called dangling pointer.

#include<stdio.h>

int *call();
int main(){
int *ptr;
ptr=call();

fflush(stdin);
printf("%d",*ptr);
return 0;
}
int * call(){

static int x=25;
++x;

return &x;
}

Output: 26

4
What is wild pointer in c?  
Answer
Explanation:
A pointer in c which has not been initialized is known as wild pointer.

Example:

What will be output of following c program?

int main(){
int *ptr;
printf("%u\n",ptr);
printf("%d",*ptr);
return 0;
}

Output: Any address
Garbage value

Here ptr is wild pointer because it has not been initialized. There is difference between the NULL pointer and wild pointer. Null pointer points the base address of segment while wild pointer doesn’t point any specific memory location.

5
What are merits and demerits of array in c?
Answer
Explanation:
Merits:

(a) We can easily access each element of array.
(b) Not necessity to declare too many variables.
(c) Array elements are stored in continuous memory location.

Demerit:

(a) Wastage of memory space. We cannot change size of array at the run time. 
(b) It can store only similar type of data.

6
Do you know memory representation of int a = 7 ?   
Answer
Explanation:
Memory representation of:

signed int a=7;         (In Turbo c compiler)
signed short int a=7 (Both turbo c and Linux gcc compiler)

Binary equivalent of data 7 in 16 bit:  00000000 00000111
Data bit: 0000000 00000111 (Take first 15 bit form right side)

Sign bit: 0 (Take leftmost one bit)

First eight bit of data bit from right side i.e. 00000111 will store in the leftmost byte from right to left side and rest seven bit of data bit i.e. 0000000 will store in rightmost byte from right to left side as shown in the following figure:   




7
What is and why array in c?
Answer
Explanation:
An array is derived data type in c programming language which can store similar type of data in continuous memory location. Data may be primitive type (int, char, float, double…), address of union, structure, pointer, function or another array.
Example of array declaration:

int arr[5];
char arr[5];
float arr[5];
long double arr[5];
char * arr[5];
int (arr[])();
double ** arr[5];

Array is useful when:

(a) We have to store large number of data of similar type. If we have large number of similar kind of variable then it is very difficult to remember name of all variables and write the program. For example:

//PROCESS ONE
int main(){
    int ax=1;
    int b=2;
    int cg=5;
    int dff=7;
    int am=8;
    int raja=0;
    int rani=11;
    int xxx=5;
    int yyy=90;
    int p;
    int q;
    int r;
    int avg;
    avg=(ax+b+cg+dff+am+raja+rani+xxx+yyy+p+q+r)/12;
    printf("%d",avg);
    return 0;
}
If we will use array then above program can be written as:

//PROCESS TWO
int main(){
    int arr[]={1,2,5,7,8,0,11,5,50};
    int i,avg;
    for(int i=0;i<12;i++){
         avg=avg+arr[i];
    }
printf("%d",avg/12);
return 0;
}

Question: Write a C program to find out average of 200 integer number using process one and two.

(b) We want to store large number of data in continuous memory location. Array always stores data in continuous memory location.

What will be output when you will execute the following program?

int main(){
int arr[]={0,10,20,30,40};
    char *ptr=arr;
    arr=arr+2;
    printf("%d",*arr);
    return 0;
}

Advantage of using array:

1. An array provides singe name .So it easy to remember the name of all element of an array.
2. Array name gives base address of an array .So with the help increment operator we can visit one by one all the element of an array.
3. Array has many application data structure.

Array of pointers in c:

Array whose content is address of another variable is known as array pointers.  For example:

int main(){
float a=0.0f,b=1.0f,c=2.0f;
float * arr[]={&a,&b,&c};
    b=a+c;
printf("%f",arr[1]);
    return 0;
}

8
Why we use do-while loop in c? Also tell any properties which you know?  
Answer
Explanation:
It is also called as post tested loop. It is used when it is necessary to execute the loop at least one time. Syntax:

do {
Loop body
} while (Expression);

Example:

int main(){
    int num,i=0;
   
    do{
         printf("To enter press 1\n");
         printf("To exit press  2");
         scanf("%d",&num);
         ++i;
         switch(num){
             case 1:printf("You are welcome\n");break;
             default : exit(0);
         }
    }
    while(i<=10);
    return 0;
}

Output: 3 3 4 4

If there is only one statement in the loop body then braces is optional. For example:

(a)
int main(){
    double i=5.5678;
    do
         printf("hi");
    while(!i);
    return 0;
}

Output: 3 3 4 4

(b)
int main(){
    double i=5.63333;
    do
         printf("hi");
    while(!i);
    return 0;
}

Output: hi

(c)
int main(){
     int x=25,y=1;
     do
       if(x>5)
         printf(" ONE");
       else if(x>10)
         printf(" TWO");
       else if(x==25)
         printf(" THREE");
       else
         printf(" FOUR");
       while(y--);
return 0;
}

Output: ONE ONE

9
What is the meaning of prototype of a function?   
Answer
Explanation:
Prototype of a function

Declaration of function is known as prototype of a function. Prototype of a function means

(1) What is return type of function?
(2) What parameters are we passing?
(3) For example prototype of printf function is:

int printf(const char *, …);

I.e. its return type is int data type, its first parameter constant character pointer and second parameter is ellipsis i.e. variable number of arguments.

10
Write a c program to modify the constant variable in c?
Answer
Explanation:
You can modify constant variable with the help of pointers. For example:

#include<stdio.h>
int main(){
    int i=10;
    int *ptr=&i;
    *ptr=(int *)20;
    printf("%d",i);
    return 0;
}

Output: 20 

11
What is pointer to a function?  
Answer
Explanation:
(1) What will be output if you will execute following code?
int * function();
int main(){
auto int *x;
int *(*ptr)();
ptr=&function;
x=(*ptr)();
printf("%d",*x);
}
int *function(){
static int a=10;
return &a;
}

Output: 10
Explanation: Here function is function whose parameter is void data type and return type is pointer to int data type.

x=(*ptr)()
=> x=(*&functyion)() //ptr=&function
=> x=function() //From rule *&p=p
=> x=&a
So, *x = *&a = a =10

(2) What will be output if you will execute following code?

int find(char);
int(*function())(char);
int main(){
int x;
int(*ptr)(char);
ptr=function();
x=(*ptr)('A');
printf("%d",x);
return 0;
}
int find(char c){
return c;
}
int(*function())(char){
return find;
}

Output: 65
Explanation: Here function whose name is function which passing void data type and returning another function whose parameter is char data type and return type is int data type.

x=(*ptr)(‘A’)
=> x= (*function ()) (‘A’) //ptr=function ()
//&find=function () i.e. return type of function ()
=> x= (* &find) (‘A’)
=> x= find (‘A’) //From rule*&p=p
=> x= 65

(3) What will be output if you will execute following code?

char * call(int *,float *);
int main(){
char *string;
int a=2;
float b=2.0l;
char *(*ptr)(int*,float *);
ptr=&call;
string=(*ptr)(&a,&b);
printf("%s",string);
return 0;
}
char *call(int *i,float *j){
static char *str="c-pointer.blogspot.com";
str=str+*i+(int)(*j);
return str;
}

Output: inter.blogspot.com
Explanation: Here call is function whose return type is pointer to character and one parameter is pointer to int data type and second parameter is pointer to float data type and ptr is pointer to such function.
str= str+*i+ (int) (*j)
=”c-pointer.blogspot.com” + *&a+ (int) (*&b)
//i=&a, j=&b
=”c-pointer.blogspot.com” + a+ (int) (b)
=”c-pointer.blogspot.com” +2 + (int) (2.0)
=”c-pointer.blogspot.com” +4
=”inter.blogspot.com”

(4) What will be output if you will execute following code?

char far * display(char far*);
int main(){
char far* string="cquestionbank.blogspot.com";
char far *(*ptr)(char far *);
ptr=&display;
string=(*ptr)(string);
printf("%s",string);
}
char far *display(char far * str){
char far * temp=str;
temp=temp+13;
*temp='\0';
return str;
}

Output: cquestionbak
Explanation: Here display is function whose parameter is pointer to character and return type is also pointer to character and ptr is its pointer.

temp is char pointer
temp=temp+13
temp=’\0’

Above two lines replaces first dot character by null character of string of variable string i.e.
"cquestionbank\0blogspot.com"

As we know %s print the character of stream up to null character.

12
Write a c program to find size of structure without using sizeof operator? 
Answer
Explanation:
struct  ABC{
    int a;
    float b;
    char c;
};
int main(){
    struct ABC *ptr=(struct ABC *)0;
    ptr++;
    printf("Size of structure is: %d",*ptr);
    return 0;
}

13
What is NULL pointer?  
Answer
Explanation:
Literal meaning of NULL pointer is a pointer which is pointing to nothing. NULL pointer points the base address of segment.

Examples of NULL pointer:

1. int *ptr=(char *)0;
2. float *ptr=(float *)0;
3. char *ptr=(char *)0;
4. double *ptr=(double *)0;
5. char *ptr=’\0’;
6. int *ptr=NULL;

What is meaning of NULL?
Answer:

NULL is macro constant which has been defined in the heard file stdio.h, alloc.h, mem.h, stddef.h and stdlib.h as
#define NULL 0

Examples:

(1)What will be output of following c program?

#include "stdio.h"
int main(){
if(!NULL)
printf("I know preprocessor");
else
printf("I don't know preprocessor");
}

Output: I know preprocessor

Explanation:
!NULL = !0 = 1
In if condition any non zero number mean true.

(2)What will be output of following c program?

#include "stdio.h"
int main(){
int i;
static int count;
for(i=NULL;i<=5;){
count++;
i+=2;
}
printf("%d",count);
}

Output: 3

(3)What will be output of following c program?

#include "stdio.h"
int main(){
#ifndef NULL
#define NULL 5
#endif
printf("%d",NULL+sizeof(NULL));
}

Output: 2
Explanation:
NULL + sizeof(NULL)
=0 + sizeoof(0)
=0+2 //size of int data type is two byte.

We cannot copy anything in the NULL pointer.

Example:

(4)What will be output of following c program?

#include "string.h"
int main(){
char *str=NULL;
strcpy(str,"c-pointer.blogspot.com");
printf("%s",str);
return 0;
}

Output: (null)

14
What is difference between pass by value and pass by reference?  
Answer
Explanation:
In c we can pass the parameters in a function in two different ways.

(a)Pass by value: In this approach we pass copy of actual variables in function as a parameter. Hence any modification on parameters inside the function will not reflect in the actual variable. For example:

#include<stdio.h>
int main(){
    int a=5,b=10;
    swap(a,b);
    printf("%d      %d",a,b);
    return 0;
void swap(int a,int b){
    int temp;
    temp =a;
    a=b;
    b=temp;
}
Output: 5    10

(b)Pass by reference: In this approach we pass memory address actual variables in function as a parameter. Hence any modification on parameters inside the function will reflect in the actual variable. For example:

#incude<stdio.h>
int main(){
    int a=5,b=10;
    swap(&a,&b);
    printf("%d %d",a,b);
    return 0;
void swap(int *a,int *b){
    int  *temp;
    *temp =*a;
    *a=*b;
    *b=*temp;
}

Output: 10 5

15
What is size of void pointer?  
Answer
Explanation:
Size of any type of pointer in c is independent of data type which is pointer is pointing i.e. size of all type of pointer (near) in c is two byte either it is char pointer, double pointer, function pointer or null pointer.  Void pointer is not exception of this rule and size of void pointer is also two byte.

16
What is difference between uninitialized pointer and null pointer?  
Answer
Explanation:
An uninitialized pointer is a pointer which points unknown memory location while null pointer is pointer which points a null value or base address of segment. For example: 

int *p;   //Uninitialized pointer
int *q= (int *)0;  //Null pointer
#include<stdio.h>
int *r=NULL;   //Null pointer

What will be output of following c program?

#include<string.h>
#include<stdio.h>
int main(){
    char *p;  //Uninitialized pointer
    char *q=NULL;   //Null pointer;
    strcpy(p,"cquestionbank");
    strcpy(q,"cquestionbank");
    
    printf("%s  %s",p,q);
    return 0;
}

Output: cquestionbank (null)

17
Can you read complex pointer declaration?
Answer
Explanation:
Rule 1. Assign the priority to the pointer declaration considering precedence and associative according to following table.


(): This operator behaves as bracket operator or function operator.

[]: This operator behaves as array subscription operator.

*: This operator behaves as pointer operator not as multiplication operator.

Identifier: It is not an operator but it is name of pointer variable. You will always find the first priority will be assigned to the name of pointer.

Data type: It is also not an operator. Data types also includes modifier (like signed int, long double etc.)

You will understand it better by examples:

(1) How to read following pointer?

char (* ptr)[3]

Answer:
Step 1: () and [] enjoys equal precedence. So rule of associative will decide the priority. Its associative is left to right so first priority goes to ().

Step 2: Inside the bracket * and ptr enjoy equal precedence. From rule of associative (right to left) first priority goes to ptr and second priority goes to *.

Step3: Assign third priority to [].

Step4: Since data type enjoys least priority so assign fourth priority to char.

Now read it following manner:

ptr is pointer to such one dimensional array of size three which content char type data. 

(2) How to read following pointer?

float (* ptr)(int)

Answer:
Assign the priority considering precedence and associative.

Now read it following manner:
ptr is pointer to such function whose parameter is int type data and return type is float type data.

Rule 2: Assign the priority of each function parameter separately and read it also separately. Understand it through following example.

(3) How to read following pointer?

void (*ptr)(int (*)[2],int (*) void))

Answer:

Assign the priority considering rule of precedence and associative.

Now read it following manner:

ptr is pointer to such function which first parameter is pointer to one dimensional array of size two which contentint type data and second parameter is pointer to such function which parameter is void and return type is int data type and return type is void

(4) How to read following pointer?

int ( * ( * ptr ) [ 5 ] ) ( )

Answer:
Assign the priority considering rule of precedence and associative.

Now read it following manner:

ptr is pointer to such array of size five which content are pointer to such function which parameter is void and return type is int type data.

(5) How to read following pointer?

double*(*(*ptr)(int))(double **,char c)

Answer:
Assign the priority considering rule of precedence and associative.

 

Now read it following manner:

ptr is pointer to function which parameter is int type data and return type is pointer to function which first parameter is pointer to pointer of double data type and second parameter is char type data type and return type ispointer to double data type.

(6) How to read following pointer?

unsigned **(*(*ptr)[8](char const *, ...)

Answer: 
Assign the priority considering rule of precedence and associative.

 

Now read it following manner:

ptr is pointer to array of size eight and content of array is pointer to function which first parameter is pointer to character constant and second parameter is variable number of arguments and return type is pointer to pointer of unsigned int data type. 

18
What are the parameter passing conventions in c?  
Answer
Explanation:
1. pascal: In this style function name should (not necessary ) in the uppercase .First parameter of function call is passed to the first parameter of function definition and so on. 

2. cdecl: In this style function name can be both in the upper case or lower case. First parameter of function call is passed to the last parameter of function definition. It is default parameter passing convention.
Examples: 

1. What will be output of following program?

int main(){
static int a=25;
void cdecl conv1() ;
void pascal conv2();
conv1(a);
conv2(a);
return 0;;
}
void cdecl conv1(int a,int b)
{
printf("%d %d",a,b);
}
void pascal conv2(int a,int b)
{
printf("\n%d %d",a,b);
}

Output: 25 0
0 25

(2) What will be output of following program?

void cdecl fun1(int,int);
void pascal fun2(int,int);
int main(){
    int a=5,b=5;
   
    fun1(a,++a);
    fun2(b,++b);
   return 0;
}
void cdecl fun1(int p,int q){
    printf("cdecl:  %d %d \n",p,q);
}
void pascal fun2(int p,int q){
    printf("pascal: %d %d",p,q);
}

Output:
cdecl:  6 6
pascal: 5 6

(3) What will be output of following program?

void cdecl fun1(int,int);
void pascal fun2(int,int);
int main(){
    int a=5,b=5;
   
    fun1(a,++a);
    fun2(b,++b);
    return 0;
}
void cdecl fun1(int p,int q){
    printf("cdecl:  %d %d \n",p,q);
}
void pascal fun2(int p,int q){
    printf("pascal: %d %d",p,q);
}

Output:
cdecl:  6 6
pascal: 5 6

(4) What will be output of following program?

void convention(int,int,int);
int main(){
    int a=5;
   
    convention(a,++a,a++);
    return 0;
}
void  convention(int p,int q,int r){
    printf("%d %d %d",p,q,r);
}

Output: 7 7 5
(5) What will be output of following program?

void pascal convention(int,int,int);
int main(){
    int a=5;
   
    convention(a,++a,a++);
    return 0;}
void pascal  convention(int p,int q,int r){
    printf("%d %d %d",p,q,r);
}

Output: 5 6 6

(6) What will be output of following program?

void pascal convention(int,int);
int main(){
    int a=1;
   
    convention(a,++a);
    return 0;
}
void pascal  convention(int a,int b){
    printf("%d %d",a,b);
}

Output: 1 2

(7) What will be output of following program?

void convention(int,int);
int main(){
    int a=1;
   
    convention(a,++a);
    return 0;}
void  convention(int a,int b){
    printf("%d %d",a,b);
}

Output: 2 2

19
What is the far pointer in c?  
Answer
Explanation:
The pointer which can point or access whole the residence memory of RAM i.e. which can access all 16 segments is known as far pointer.

Size of far pointer is 4 byte or 32 bit. Examples:

(1) What will be output of following c program?

int main(){
int x=10;
int far *ptr;
ptr=&x;
printf("%d",sizeof ptr);
return 0;
}

Output: 4

(2)What will be output of following c program?

int main(){
int far *near*ptr;
printf("%d %d",sizeof(ptr) ,sizeof(*ptr));
return 0;
}

Output: 4 2
Explanation: ptr is far pointer while *ptr is near pointer.

(3)What will be output of following c program?

int main(){
int far *p,far *q;
printf("%d %d",sizeof(p) ,sizeof(q));
}

Output: 4 4

First 16 bit stores: Segment number
Next 16 bit stores: Offset address

Example:

int main(){
int x=100;
int far *ptr;
ptr=&x;
printf("%Fp",ptr);
return 0;
}

Output: 8FD8:FFF4
Here 8FD8 is segment address and FFF4 is offset address in hexadecimal number format.

Note: %Fp is used for print offset and segment address of pointer in printf function in hexadecimal number format.
In the header file dos.h there are three macro functions to get the offset address and segment address from far pointer and vice versa.

1. FP_OFF(): To get offset address from far address.
2. FP_SEG(): To get segment address from far address.
3. MK_FP(): To make far address from segment and offset address.

Examples:
(1)What will be output of following c program?

#include "dos.h"
int main(){
int i=25;
int far*ptr=&i;
printf("%X %X",FP_SEG(ptr),FP_OFF(ptr));
}

Output: Any segment and offset address in hexadecimal number format respectively.

(2)What will be output of following c program?

#include "dos.h"
int main(){
int i=25;
int far*ptr=&i;
unsigned int s,o;
s=FP_SEG(ptr);
o=FP_OFF(ptr);
printf("%Fp",MK_FP(s,o));
return 0;
}

Output: 8FD9:FFF4 (Assume)
Note: We cannot guess what will be offset address; segment address and far address of any far pointer .These address are decided by operating system.

Limitation of far pointer:

We cannot change or modify the segment address of given far address by applying any arithmetic operation on it. That is by using arithmetic operator we cannot jump from one segment to other segment. If you will increment the far address beyond the maximum value of its offset address instead of incrementing segment address it will repeat its offset address in cyclic order.

Example:

(q)What will be output of following c program?

int main(){
int i;
char far *ptr=(char *)0xB800FFFA;
for(i=0;i<=10;i++){
printf("%Fp \n",ptr);
ptr++;
}
return 0;
}

Output:

B800:FFFA
B800:FFFB
B800:FFFC
B800:FFFD
B800:FFFE
B800:FFFF
B800:0000
B800:0001
B800:0002
B800:0003
B800:0004

This property of far pointer is called cyclic nature of far pointer within same segment.

Important points about far pointer:

1. Far pointer compares both offset address and segment address with relational operators.

Examples:

(1)What will be output of following c program?

int main(){
int far *p=(int *)0X70230000;
int far *q=(int *)0XB0210000;
if(p==q)
printf("Both pointers are equal");
else
printf("Both pointers are not equal");
return 0;
}

Output: Both pointers are not equal

(2)What will be output of following c program?

int main(){
int far *p=(int *)0X70230000;
int far *q=(int *)0XB0210000;
int near *x,near*y;
x=(int near *)p;
y=(int near *)q;
if(x==y)
printf("Both pointer are equal");
else
printf("Both pointer are not equal");
return 0;
}

Output: Both pointers are equal

2. Far pointer doesn’t normalize.

20
What is a cyclic property of data type in c? Explain with any example. 
Answer
Explanation:
#include<stdio.h>
int main(){
    signed char c1=130;
    signed char c2=-130;
    printf("%d  %d",c1,c2);
    return 0;
}

Output: -126   126 (why?)
This situation is known as overflow of signed char. 
Range of unsigned char is -128 to 127. If we will assign a value greater than 127 then value of variable will be changed to a value if we will move clockwise direction as shown in the figure according to number. If we will assign a number which is less than -128 then we have to move in anti-clockwise direction.



Pointers Interview questions     
Data types Interview questions    
Advance interview questions    
String interview questions and answers          
Commonly asked questions     
TCS placement question

126 comments:

  1. Making a C program, to record the subjects taken by a student, the subjects removed, the approved and disapproved and calculate the GPA for that semester.

    The program should have the option of "going out"

    ReplyDelete
  2. Superb collection..thanks !!
    just one bug to notify in Q.14..printf("Size of structure is: %d",*ptr); *ptr should be changed to ptr

    ReplyDelete
  3. Question 14 is correct one. No bug. It will work only Turbo c3.0

    ReplyDelete
  4. woov very good post.. thanks a lot to author...

    ReplyDelete
  5. superr collectionnnnnnn.............

    ReplyDelete
  6. great job what a super collectionnnnnnnnnnnn

    ReplyDelete
  7. i want a c program that will display this output:
    A B C D E F G F E D C B A
    A B C D E F F E D C B A
    A B C D E E D C B A
    A B C D D C B A
    A B C C B A
    A B B A
    A A

    ReplyDelete
    Replies
    1. // This program is written in JAVA language .Which language u r using u can change

      public class BB5
      {
      public static void main(String aa[])
      {
      int n=20;
      int a=1;
      int b=n/2;
      int c=65+b;
      for(int k=1;k<=(n/2+1);k++)
      {
      for(int i=65;i<=c;i++)
      {
      System.out.printf("%c",i);

      }

      for(int j=65+b;j>=65;j--)
      {
      System.out.printf("%c",j);

      }
      c--;
      b--;
      System.out.println();
      }
      }
      }

      Delete
    2. good site .create site gives information for c++,java,DBMS,unix

      Delete
    3. #include

      int main (){
      unsigned int j;
      unsigned char i;
      for(j=0;j<7;j++){
      for(i = 'a';i <= ('g' - j);i++)
      printf("%c", i);

      for(i = ('g' - j);i >= 'a';i--)
      printf("%c", i);

      printf("\r\n");
      }
      return ;
      }

      Delete
    4. /*This program written in C Language*/
      #include
      main()
      {
      char i,j,k;
      for(i='G';i>='A';i--)
      {
      for(j='A';j<=i;j++)
      {
      printf("%c",j);
      }
      for(k=i;k>='A';k--)
      {
      printf("%c",k);
      }
      printf("\n");
      }
      }

      Delete
  8. Wonderful site.The effort of the site-creator is commendable.Keep it up.Your info. was quite useful.

    ReplyDelete
  9. great post!!

    ReplyDelete
  10. #include

    void main()
    {

    int no_of_lines, alphabet = 65, i, count, j;

    printf("\nenter the number of lines you want to print\t:");
    scanf("%d",&no_of_lines);
    count=2*no_of_lines;
    for(j=0;j<no_of_lines;j++)
    {
    if(j==0)
    {
    printf("\n\n");
    for(i=0;i<count;i++)
    {
    if(i<no_of_lines)
    {
    printf(" %c", alphabet++);
    }
    else if(i == no_of_lines)
    {
    alphabet--;
    }
    else
    {
    printf(" %c",--alphabet);
    }
    }
    }
    else
    {
    printf("\n");
    //printf("\nnothing\n");
    for(i=0;i<count-2*j;i++)
    {
    if(i<no_of_lines-j)
    {
    printf(" %c", alphabet++);
    }
    else
    {
    printf(" %c",--alphabet);
    }
    }

    }
    }
    }


    SAMPLE OUTPUT:

    enter the number of lines you want to print : 5

    A B C D E D C B A
    A B C D D C B A
    A B C C B A
    A B B A
    A A

    if u want dat particular format enter the number of lines as 7....

    ReplyDelete
  11. Great work ..Lots of hard work ...thanks a lot..becz it helps me a lot

    ReplyDelete
  12. main()
    {
    float a=0.7;
    if(a<0.7)
    printf("c");
    else
    printf("c++");
    }

    output:c

    Can anybody explain this plz

    ReplyDelete
    Replies
    1. yup the (0.7) in the if statement is by default double type
      and float is always less as to double!!
      so,float a=0.7 is always less than (0.7 which has it's default datatype double)!!

      :-)

      Delete
    2. In the above program a is float value and 0.7 value directly substituted in program that value take double datatype.
      -- float takes after dot(.) 8 zero's.
      -- Double takes after dot(.) 16 zero's.
      so.....float is always less than double.
      Output of this program is C

      Delete
  13. Hi Anil,

    Check the question(4) of following link
    http://cquestionbank.blogspot.com/2010/04/c-questions-answers.html

    I think It will help you.

    ReplyDelete
  14. main()
    {
    float a=0.7;
    if(a<0.7)
    printf("c");
    else
    printf("c++");
    }


    Exp:
    in the above program the compiler take it('a') as 0.7000001,so a<0.7 i.e true.so ,it's o/p is "c".

    ReplyDelete
  15. its not enough to learn "c" need some more, this is very nice collection,thank full to you

    ReplyDelete
  16. void main()
    {
    int i;
    char j;
    for(i=71;i>=65;i--)
    {
    for(j=65;j<=i;j++)
    {
    printf("%c",j);
    }
    printf("\n");
    }


    output:-
    ABCDEFG
    ABCDEF
    ABCDE
    ABCD
    ABC
    AB
    A

    ReplyDelete
  17. void main()
    {
    int i;
    char j,k;
    for(i=71;i>=65;i--)
    {
    for(j=65;j<=i;j++)
    {
    printf("%c",j);
    }
    for(k=i;k>=65;k--)
    {
    printf("%c",k);
    }
    printf("\n");
    }


    output:-
    ABCDEFGFEDCBA
    ABCDEFFEDCBA
    ABCDEEDCBA
    ABCDDCBA
    ABCCBA
    ABBA
    AAA

    ReplyDelete
    Replies
    1. #include
      int main()
      {
      int a,n=7,i,c;
      for(i=0;i<=n;i++)
      {for(c=0;c<=(n-i);c++)
      printf(" ");
      for(c=0,a=65;c<=i;c++,a++)
      printf("%c",a);
      printf("\n");
      }
      n++;
      for(i=n;i<=16;i++)
      {
      for(c=0;c<=n-i;c++)
      printf(" ");
      for(c=0,a=65;c<=(2*n-i);c++,a++)
      printf("%c",a);

      printf("\n");
      }
      return 0;
      }
      out put is :
      A
      A B
      A B C
      A B C D
      A B C D E
      A B C D
      A B C
      A B
      A

      Delete
  18. C is a very interesting language and this is a basic of all language, if we have no knowledge of c then we cant understand c++, this is a 1st stage of all programing language.

    ReplyDelete
  19. Great! this post is very help for me.

    ReplyDelete
  20. Great work...really worthable one

    ReplyDelete
  21. awesum collection...

    ReplyDelete
  22. Awesome awesome awesome awesome awesome.......

    ReplyDelete
  23. really...helpful

    ReplyDelete
  24. awesome awesome awesome awesome awesome awesome awesome awesome awesome awesome awesome xcllnt work..............:))))))

    ReplyDelete
  25. great post

    ReplyDelete
  26. good but need little more

    ReplyDelete
  27. all questions are very easy questions pls post difficult question and their answers

    ReplyDelete
  28. Thanks u vary much to create such super blog

    ReplyDelete
  29. thank you sooooooooooooooooooooooo much...i find these questions so very useful...i could now confidently face my placement interviews..thanks once again..

    ReplyDelete
  30. I need answer for this question immediately before 3 hrs .. pls help me

    1.write a c program to divide the no. 73897869by 256 without using +,-,/,* and loop statement??

    ReplyDelete
  31. and this too!

    write 2 main () independent functions without using comments in a single program..pls help me friends i need the answer the answer immediately

    ReplyDelete
  32. Wow....thats great. I have my Class Notes on C Programming. I shared them in my blog

    Tanmay On Run

    But your posts are much more helpful, My post will be helpful for class notes. But these posts are helpful for practicing. Nice to find your blog.

    ReplyDelete
  33. This is awesome post and good imformation
    C interview questions

    ReplyDelete
  34. 1)void main()
    {
    float a=2.1;
    if(a==2.1)
    printf("TE");
    else
    printf("BE");
    getch();
    }
    ------------------------------------------------------
    Whats the OUTPUT of Following Program
    2)void main()
    {
    float a=2.0;
    if(a==2.0)
    printf("TE");
    else
    printf("BE");
    getch();
    }
    give Ans with reason....:)

    ReplyDelete
  35. Hi Anurag,
    Please check the question (1) of the following link: http://cquestionbank.blogspot.com/2009/09/c-operator-question-with-detial.html

    I hope it will help you.

    ReplyDelete
  36. thanks a lot sir..........

    ReplyDelete
  37. super..................site,&&&&&&&&&&&&&&&
    super collection.

    ReplyDelete
  38. very very helpful, thank you!

    ReplyDelete
  39. thanks............
    supper.....D:)

    ReplyDelete
  40. i didnt even expect this much of material ..thanq :) i think it definitly helps me alot..:)

    ReplyDelete
  41. In the program for dangling pointer if ptr=call()
    is written before clrscr() then it prints garbage value ...if written after it prints 26 correctly......Plz explain this..........using turbo C

    ReplyDelete
  42. Write a program for a GENERAL NUMBER CONVERTERS which include
    binary, decimal, octa and hexadecimal. You need to write the program using C
    language.

    ReplyDelete
  43. Hi,
    I hope this link will help you
    http://cquestionbank.blogspot.com/2010/07/c-program-examples.html

    Check Conversion ( Number System ) section

    ReplyDelete
  44. well frnd i have a question---

    why the constructor in c++ can't be virtual but destructor can be?

    ReplyDelete
  45. I really appreciate this. I shall donate some to this site.

    ReplyDelete
  46. This is very use full for students....

    ReplyDelete
  47. really good collection.....very useful

    ReplyDelete
  48. Anyone plz peast link to find turbo C for windows-7.
    i have turboC.exe setup but not working properlly.

    ReplyDelete
  49. Count the total words in a sentence,count once if word repeatting without using lib function.

    eg- my name is jawed,my pet name is dog.

    Answer-6

    ReplyDelete
  50. all genius....
    great work...

    ReplyDelete
  51. void main()
    {
    float a=2.1;
    if(a==2.1)
    printf("TE");
    else
    printf("BE");
    getch();
    }

    In the above program a is float value but 2.1 value directly substituted in program taht value take double datatype.
    -- float takes after dot(.) 8 zero's.
    -- Double takes after dot(.) 16 zero's.
    so.....float is not equal to double.

    ans is BE.

    ReplyDelete
  52. write a program to find the rank of the number in the one dimensional array without using sorting and using two arrays

    ReplyDelete
  53. c++ has any site like c

    ReplyDelete
  54. nice job i didn't see this type of stuff .Why don't you make website, we will made website with low price consult us sankar00002009@gmail.com

    ReplyDelete
  55. yes. good

    ReplyDelete
  56. #include
    #include
    void main()
    {
    int i,j;
    clrscr();
    for(i=9;i>=1;i++)
    {
    for(j=i-1;j<=i;j--)
    {
    printf("%d",j);
    }
    printf("\n");
    }
    getch();
    }

    ReplyDelete
  57. I Think of your talents as the things you’re really good at. They’re like personality traits. For instance, you may be a very creative person, or a person who’s really good at attending to details or a person with a gift for communicating. Your talents are the base for any successful business venture, including a home-based business.

    ReplyDelete
  58. wonderful info abt C

    ReplyDelete
  59. information is very good

    ReplyDelete
  60. great job, really wonderful info.

    ReplyDelete
  61. very well written and organized tutorials…its indeed a great help for beginners like me to keep up the interest and at the same time learn this important subject.
    Cbse Entrancei

    ReplyDelete
  62. really very useful..thnks a lot

    ReplyDelete
  63. Anshul Jain6/29/12, 1:28 AM

    This is really an awesome blog!!!
    Way to go!!!

    ReplyDelete
  64. Thanks a lot. this helps a lot for fast revision of C.

    ReplyDelete
  65. *hi can u suggest me a good ebook for Recursion in C??
    I cant understand recursion :(
    plz help me out...

    ReplyDelete
  66. it's is very useful..............

    ReplyDelete
  67. can u write a code of this output:
    Enter a number:12345
    :23451
    :34512
    :45123
    :51234
    The highest number:51234

    ReplyDelete
    Replies
    1. #include
      #include

      char *
      rotate(char *str)
      {
      char *cp = str;
      char ch = *cp++;
      int i;

      while (*cp) {
      *(cp-1) = *cp++;
      }
      *(cp-1) = ch;

      return str;
      }

      void
      shuffle(char *str)
      {
      long bigval = 0;
      int i;
      long val = 0;

      printf("Shuffling...\n");

      for (i=0; i < strlen(str); i++) {
      printf("%s\n", str = rotate(str));
      val = atol(str);
      if (!bigval || val > bigval ) {
      bigval = val;
      }
      }

      printf("Biggest shuffle is %d\n", bigval);

      }

      main()
      {
      char buf[64];
      printf("\nEnter +ve number : ");
      scanf("%s",&buf);
      shuffle(buf);
      }

      Delete
  68. and this..
    Enter a length of line:5
    Enter P1:maria
    Enter P1:greg
    Enter P1:juan
    Enter P1:bitoy
    Enter P1:melai
    SAVE:4

    I'LL wait ur reply.. i need it so badly

    ReplyDelete
  69. i need a program for this

    1
    2 3
    4 5 6
    7 8 9 10

    ReplyDelete
    Replies
    1. void main()
      {
      int j,i,k;
      k=1;
      for(i=1;i<=4;i++)
      {
      for(j=i;j<=i;j++)
      {
      printf("%d",k);
      k++;
      }
      printf("/n");
      }
      }

      Delete
    2. // this is correct , just check it , run it

      #include "stdio.h"

      int main()
      {
      int j,i,k;
      k=1;
      for(i=1;i<=4;i++)
      {
      for(j=0;j<i;j++)
      {
      printf("%d ",k);
      k++;
      }
      printf("\n");
      }
      return 0;
      }

      Delete
  70. #include
    #include
    void main()
    {
    printf("1
    2 3
    4 5 6
    7 8 9 10");
    getch();
    }

    ReplyDelete
  71. without loops.......use \t for tabs


    void main()
    {
    printf("1\n2 3\n4 5 6\n7 8 9 10");

    }

    ReplyDelete
  72. hii frnds, i am starting to learn C programming language ....but it seems so difficult, i m studying "LET US C".It is very tuff to understand the concept of looping & Decision making questions...so frnds please me guideline how can i improve my learning....coz i want to make my carier in programming.

    ReplyDelete
  73. Please add some more question like..
    1.Diff. btw c and c++,
    2.Diff btw c++,C,java.
    3.what is deceleration and definition.

    ReplyDelete
  74. Thank's for providing valuable information,it help's to me............

    ReplyDelete
  75. Thank you admin.

    ReplyDelete
  76. Kudos to the Blogger!
    Keep up your good work.

    ReplyDelete
  77. hey have you done programming using calloc and malloc?
    I am not able to find out...plz tell me where it is?

    ReplyDelete
  78. thanks for your information...

    They are useful everyone for developing career...

    good work keep it up...

    ReplyDelete
  79. what is the output for following query:
    1.select greatest(94,'845','846') from dual;
    2.select greatest('94','845',846) from dual; can anyone explain me plz

    ReplyDelete
  80. Very Useful information. Commented by Bukkas

    ReplyDelete
  81. how to write a c program to find birth year by NIC number

    ReplyDelete
  82. hi frds i need ur help can anybody tell me the program for this algorithm??plz send to my mail id sasiviji95@gmail.com as soon as possible plz frds it's my request,,
    write a c++ program to print the following triangle
    5
    4 5
    3 4 5
    2 3 4 5
    1 2 3 4 5
    algorithm:
    s1:start the program
    s2:
    declare i,jand n as int data type
    s3:read the number of lines
    s4:fori=n to greater then or equal to 0
    s4.1:for j=i to less than n print y
    s5: stop the program
    output:
    enter number of lines 5
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5

    ReplyDelete
    Replies
    1. plz type the program this output display in c lang

      Delete
  83. your blog is soo use full and ur c skills are awesm :)

    ReplyDelete
  84. Pass by reference is NOT possible in C.

    The program will work however its not an example of "pass by reference"

    ReplyDelete
  85. IN the 10th question........where is const variable???

    ReplyDelete
  86. int main(){
    float a=0.0f,b=1.0f,c=2.0f;
    float * arr[]={&a,&b,&c}; // ************
    b=a+c;
    printf("%f",arr[1]);
    return 0;
    }

    hy this is producing an error :Illegal Initialization I have marked that line by ******.......
    Plz help

    ReplyDelete
  87. What is difference between dequeue and deque?

    ReplyDelete
  88. Please make a program to reverse the string "MY NAME IS KHAN" to "KHAN IS MY NAME".

    ReplyDelete
  89. what is memory representation of 5.235!!!!!!

    ReplyDelete
  90. where is the answers????????????

    ReplyDelete
  91. good good,thanxxxxxxxxxxxxxxx

    ReplyDelete
  92. the way you explain in q17 is awesome I hve ever read.. :)

    ReplyDelete
  93. void main()
    {
    int i=30;
    int j=40;
    printf("%d..%d");
    getch();
    }
    output- 40..30
    plz tell m logic used in this prog.

    ReplyDelete
  94. yeah man this is it all you need good work

    ReplyDelete
  95. awesome !! great explanation !!!!! very thanq sir :)

    ReplyDelete
  96. your blog is soo use full and ur c skills are awesm :)

    ReplyDelete
  97. hello frnds
    any logic bits are there
    plz tell me
    help me

    ReplyDelete
  98. write a program in c input 1 and the output 100 anybody rly me pls

    ReplyDelete
  99. setup an internet connection and share this connection using proxy server with limited service that is only HTTP and FTP? please friends answer the quetion............

    ReplyDelete
  100. Write a "C" programe to show weekday when input 1 show Monday 2 tuesday as show on using the switch statement? give me answer the que..........

    ReplyDelete
  101. What is the output of the following code segment?
    int i=1;
    do
    while(i++<=5);
    while(i++<=4);
    while(i++<=3);
    printf(“%d”,i);

    ReplyDelete
  102. What is the output of the following code segment?
    int i=1;
    while(i++<5);
    printf("%d",i);

    ReplyDelete
  103. http://c4campus.blogspot.in/
    where you can get campus related help like c & data structure mcq and discriptive type questions and answers, and also java,dbms,technical+hr interview questions..

    ReplyDelete