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:

A dangling pointer arises when it continues to reference a memory address that once held a variable but has since been deallocated. This situation is commonly referred to as the 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: Certain compilers may issue a warning message when returning the address of a local variable or a temporary.

Explanation: The variable 'x' is a local variable, confined to the scope and lifetime of the function call. Consequently, after returning the address of 'x', the variable 'x' becomes invalid, while the pointer 'ptr' persists in 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:
An uninitialized pointer in C is commonly referred to as a "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

In this context, 'ptr' is deemed a wild pointer due to its lack of initialization. It's crucial to distinguish between a NULL pointer and a wild pointer. A NULL pointer points to the base address of a segment, serving as a deliberate indication of no specific memory location, whereas a wild pointer lacks such a targeted assignment.

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

Advantages:

(a) Facilitates straightforward access to each array element. (b) Reduces the need for an excessive number of variable declarations. (c) Ensures the storage of array elements in contiguous memory locations.

Drawbacks:

(a) Incurs memory wastage, and the array size cannot be altered dynamically during runtime. (b) Restricts the storage capability to a singular data type.



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

Memory Representation:

For signed int a = 7; in Turbo C Compiler:

Binary equivalent of data 7 in 16 bits: 00000000 00000111 Data bits: 0000000 00000111 (Take the first 15 bits from the right side)

Sign bit: 0 (Take the leftmost one bit)

The first eight bits of the data bits from the right side, i.e., 00000111, will be stored in the leftmost byte from right to left side. The remaining seven bits of the data bits, i.e., 0000000, will be stored in the rightmost byte from right to left side.

For signed short int a = 7 in both Turbo C and Linux GCC Compiler:

Binary equivalent of data 7 in 16 bits: 00000000 00000111 Data bits: 0000000 00000111 (Take the first 15 bits from the right side)

Sign bit: 0 (Take the leftmost one bit)

The first eight bits of the data bits from the right side, i.e., 00000111, will be stored in the leftmost byte from right to left side. The remaining seven bits of the data bits, i.e., 0000000, will be stored in the rightmost byte from right to left side.





7
What is and why array in c?
Answer
Explanation:

An array in the C programming language is a composite data type capable of storing elements of the same data type in contiguous memory locations. These elements may include primitive types such as int, char, float, double, as well as more complex types like the address of a 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) Arrays are particularly advantageous when dealing with a substantial volume of data of the same type. In scenarios where numerous variables of a similar kind are involved, it becomes cumbersome to individually name and manage each variable within a program. This challenge can be efficiently addressed by utilizing arrays. Instead of maintaining a lengthy list of variable names, an array provides a compact and organized way to store and process a large set of homogeneous data. This not only simplifies the code-writing process but also enhances program readability and maintainability.

For instance, consider the following scenario without using an array:

int ax=1, b=2, cg=5, dff=7, am=8, raja=0, rani=11, xxx=5, yyy=90, p, q, r, avg; avg = (ax + b + cg + dff + am + raja + rani + xxx + yyy + p + q + r) / 12; printf("%d", avg);


In contrast, the array-based approach significantly improves code conciseness:

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


Utilizing arrays in this manner streamlines code, reduces the likelihood of errors, and enhances the overall efficiency of handling large datasets.


//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) Arrays offer a compelling solution when there is a need to store a considerable amount of data in a contiguous memory location. One of the key advantages of arrays is their inherent ability to ensure that elements are stored sequentially in memory. This contiguous allocation facilitates efficient access to elements through indexing, as memory locations are adjacent. This contrasts with non-array data structures where elements may be scattered in memory, leading to less predictable access patterns.

For instance, when dealing with a large dataset, the use of arrays ensures that the elements are stored consecutively, promoting efficient memory utilization and facilitating faster retrieval. This characteristic becomes especially beneficial when there is a requirement for sequential processing or when direct access to specific elements is crucial. In scenarios where data locality is essential for performance, arrays provide a straightforward and reliable mechanism for achieving continuous memory storage.



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;
}

Advantages of using arrays:

Conciseness and Easy Naming:
Arrays offer a concise way to represent a collection of elements under a single name. This simplifies the code and makes it easier to manage and remember the names of individual elements within the array.

Efficient Element Access:
The array name provides the base address of the array. Utilizing the increment operator, it becomes straightforward to sequentially visit each element of the array. This efficient access to elements is especially beneficial when performing operations or computations on the entire array.

Applications in Data Structures:
Arrays play a fundamental role in various data structures. Their ordered and contiguous nature makes them well-suited for implementations of essential data structures such as stacks, queues, and matrices. This versatility contributes to the effectiveness of arrays in organizing and manipulating data in different computational scenarios.


Array of Pointers in C:

An array of pointers in C is a composite data structure where each element of the array holds the address of another variable. This arrangement is particularly useful when dealing with multiple variables, and the array of pointers acts as a collection of references to these variables. Here's an example for better illustration:


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:
This loop, alternatively known as a post-tested loop, is employed when it is essential to ensure the execution of the loop at least once. The syntax is as follows:

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 the loop body consists of only one statement, the use of braces becomes 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

The declaration of a function is referred to as the prototype of the function. The prototype encompasses the following information:

  1. The return type of the function.
  2. The parameters that the function accepts.

For instance, the prototype of the printf function is as follows:

int printf(const char *, …);

Namely, the return type of printf is of integer data type. Its first parameter is a constant character pointer, and the second parameter is specified as an ellipsis, indicating a variable number of arguments.

10
Write a c program to modify the constant variable in c?
Answer
Explanation:
Constant variables can be modified through the use of pointers. For instance:

#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: In this context, a 'function' refers to a function with a parameter of void data type and a return type of a pointer to int.
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: In this scenario, the function named 'function' takes a parameter of void data type and returns another function. The returned function, in turn, accepts a parameter of char data type and has a return type of int.

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: The function named 'call' has a return type of a pointer to character. It takes two parameters: one is a pointer to int data type, and the other is a pointer to float data type. The pointer 'ptr' is declared to point to this 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: The function 'display' is defined with a parameter of a pointer to character and a return type of a pointer to character. The pointer 'ptr' is assigned to point to this function.

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

In the given context, the two lines entail the replacement of the first dot character in the string variable 'cquestionbank\0blogspot.com' with a null character. It's worth noting that the '%s' format specifier is employed to print characters from the stream up to the null character in a string.

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:
The literal meaning of a NULL pointer is a pointer that points to nothing, signifying the absence of a valid memory location. In practice, a NULL pointer typically points to the base address of a segment. Examples of NULL pointers include:

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 a macro constant defined in header files such as stdio.h, alloc.h, mem.h, stddef.h, and stdlib.h. It is commonly employed to represent a null pointer, indicating that the pointer does not point to any valid memory location.

#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:
In logical terms, the expression !NULL = !0 = 1 asserts that the negation of a null condition or zero evaluates to true, represented by the value 1. In an 'if' condition, any non-zero number is considered 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.

Copying is not permissible with a NULL pointer, as it denotes the absence of a valid memory location and attempting to copy data to or from it can lead to undefined behavior.

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, parameters can be passed to a function using two distinct methods.

(a) Pass by value: In this approach, a copy of the actual variables is passed to the function as parameters. Consequently, any modifications made to these parameters within the function do not affect the original variables. 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 the memory address of the actual variables to the function as parameters. Consequently, any modifications made to these parameters within the function directly impact the original variables. 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:
The size of any type of pointer in C is independent of the data type it points to. Regardless of whether it's a char pointer, double pointer, function pointer, or null pointer, the size of all near pointers in C is two bytes. This rule extends to void pointers as well; their size is also two bytes.

16
What is difference between uninitialized pointer and null pointer?  
Answer
Explanation:
An uninitialized pointer is a pointer that points to an unknown memory location, whereas a null pointer is a pointer that points to a null value or the base address of a 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 priority to the pointer declaration by considering precedence and associativity according to the following table.


(): This operator functions as a bracket or function operator.

[]: This operator acts as the array subscription operator.

*This operator functions as the pointer operator, distinct from its use as a multiplication operator.

Identifier: Although not classified as an operator, it represents the name of the pointer variable. Priority is consistently assigned to the name of the pointer.

Data type: Similarly not categorized as an operator, data types encompass modifiers (e.g., signed int, long double, etc.).

Understanding these concepts is better illustrated through examples:


(1) How to read following pointer?

char (* ptr)[3]

Answer:
Step 1: The operators () and [] share equal precedence. As per the rule of associativity (left to right), the first priority is assigned to ().

Step 2: Within the brackets, * and ptr have equal precedence. According to the right-to-left rule of associativity, the first priority is assigned to ptr, and the second priority goes to *.

Step 3: Assign the third priority to [].

Step 4: As the data type has the least priority, assign the fourth priority to char.

Now, read it in the following manner:

"ptr is a pointer to a one-dimensional array of size three, which contains char-type data."


(2) How to read following pointer?

float (* ptr)(int)

Answer:
Assign the priority by considering precedence and associativity.

Now, read it in the following manner:

'ptr is a pointer to a function whose parameter is of int type and return type is of float type.'

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


(3) How to read following pointer?

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

Answer:

Assign the priority considering the rule of precedence and associativity.

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 the rule of precedence and associativity.

Now read it in the following manner:

"ptr is a pointer to an array of size five, where the contents are pointers to functions with a parameter of void type and a return type of int."


(5) How to read following pointer?

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

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

 

Now read it in the following manner:

ptr is a pointer to a function with a parameter of int type and a return type of a pointer to a function. The function it points to has the first parameter as a pointer to a pointer of double data type, the second parameter as a char type data, and the return type as a pointer to double data type.


(6) How to read following pointer?

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

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

 

Now read it in the following manner:

"ptr is a pointer to an array of size eight, where the contents of the array are pointers to functions. The functions have the first parameter as a pointer to a constant character, the second parameter as a variable number of arguments, and the return type as a pointer to a pointer of unsigned int data type."  


18
What are the parameter passing conventions in c?  
Answer
Explanation:
  1. 1. Pascal: In this style, the function name (not necessarily) is in uppercase. Parameters in the function call are passed to the corresponding parameters in the function definition, maintaining the order.


  2. 2. Cdecl: In this style, the function name can be in both uppercase or lowercase. The first parameter of the function call is passed to the last parameter of the function definition. It is the default parameter passing convention.

Examples could be provided for each style to illustrate their usage.


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:
A far pointer is a type of pointer in a computer program that can access or point to the entire addressable memory of RAM. Specifically, it can access all 16 segments of the memory.

The size of a far pointer is 4 bytes or 32 bits. 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 a far pointer, whereas *ptr is a 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

The first 16 bits store the segment number, while the next 16 bits store the offset address.

Example:

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

Output: 8FD8:FFF4

In the given context, '8FD8' represents the segment address, and 'FFF4' represents the offset address in hexadecimal number format.

Note: %Fp is used to print the offset and segment address of a pointer in the printf function in hexadecimal number format.

The header file 'dos.h' provides three macro functions for working with far pointers:

  1. 1.FP_OFF(): Used to obtain the offset address from a far address.
  2. 2.FP_SEG(): Used to obtain the segment address from a far address.
  3. 3.MK_FP(): Used to create a far address from segment and offset addresses.

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: The offset address, segment address, and far address of any far pointer are determined by the operating system and cannot be predicted.

Limitation of far pointer:

It is not possible to change or modify the segment address of a given far address by applying any arithmetic operation on it. In other words, using arithmetic operators, we cannot jump from one segment to another. If the far address is incremented beyond the maximum value of its offset address, instead of incrementing the segment address, it will repeat its offset address in a 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 a far pointer, wherein it exhibits a cyclic nature within the same segment, is referred to as the cyclic nature of far pointers within the same segment.

Important points about far pointers:

  1. Far pointers compare both offset address and segment address using 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 a signed char. The range of an unsigned char is -128 to 127. If a value greater than 127 is assigned, the variable's value will wrap around to a new value by moving in the clockwise direction, as depicted in the figure according to the number line. Similarly, assigning a number less than -128 requires moving in the anti-clockwise direction.



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

230 comments:

«Oldest   ‹Older   201 – 230 of 230
Unknown said...

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

question no 8
how come output is this??
this is wrong
we r not printing any value

Unknown said...

Programming in c by Stephen kochain and expert in c
You can also refer numerical recipes inc

Unknown said...

Nice site and nice ques
Plz upload some more questions

Unknown said...

wow.......this is helpfull blog.....

Unknown said...

I can't understand the meaning for third questions answer.Can u please explain me....?

online idea lab said...
This comment has been removed by the author.
Unknown said...

It's great job and more useful to others

Anonymous said...

Hello there!
I'm Simran from Receptix - a job search portal. I stumbled on your website and I must say it envelopes great information.
Coincidentally, we have a video designed on a topic similar to your blog post on interview questions on C language. I was wondering that incorporating this video can further enhance the user experience on your page. Here's the link to the video
https://www.youtube.com/watch?v=WPnURgypr9U
It will be great if you could also mention www.receptix.com as the source, along with the video.
Look forward to this content synergy.
Thanks

sureshshetty said...

Thank for this blog are more informative step by step and useful contents. I here by attached my site would you see this blog

7 tips to start a career in digital marketing

“Digital marketing is the marketing of product or service using digital technologies, mainly on the Internet, but also including mobile phones, display advertising, and any other digital medium”. This is the definition that you would get when you search for the term “Digital marketing” in google. Let’s give out a simpler explanation by saying, “the form of marketing, using the internet and technologies like phones, computer etc”.

we have offered to the advanced syllabus course digital marketing for available join now

more details click the link now

https://www.webdschool.com/web-development-course-in-chennai.html

sureshshetty said...

Amazing blog useful information

Web designing trends in 2020

When we look into the trends, everything which is ruling today’s world was once a start up and slowly begun getting into. But Now they have literally transformed our lives on a tremendous note. To name a few, Facebook, Whats App, Twitter can be a promising proof for such a transformation and have a true impact on the digital world.

we have offered to the advanced syllabus course web design and development for available join now

more details click the link now

https://www.webdschool.com/web-development-course-in-chennai.html

Travelinmyway said...

Great good questions keep it up
Learnprogramo.

Bhavana said...

Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites! 360DigiTMG PMP Certification

PMP Certification in Malaysia
PMP Course

PMP Course in Malaysia

Bhavana said...

I was just browsing through the internet looking for some information and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject. Bookmarked this page, will come back for more.
360DigiTMG PMP Certification
360DigiTMG PMP Course in malaysia
360DigiTMG PMP Course
360DigiTMG PMP Training in malaysia
360DigiTMG PMP Training

MS Dynamics said...

It was a great information and Its really worth reading it.
Online Training
software training institute
online classes

Data Science Training said...

Amazing blog with unique information found valuable and enjoyed reading this one. Keep posting. Thanks for sharing.
Data Science Training in Hyderabad

Huongkv said...

Mua vé máy bay tại đại lý Aivivu, tham khảo

giá vé máy bay đi Mỹ khứ hồi

vé máy bay từ mỹ về việt nam hãng eva

lịch bay hà nội nha trang

giá vé máy bay sài gòn - phú quốc

vé máy bay đi huế vietnam airlines

Eat In Bangalore said...
This comment has been removed by the author.
Lets Talk Tech said...

This is so helpful, thanks for the detailed explanation. You could find more question on C from here

pushpam abhishek said...

Great work sir Thank you
for more at https://www.trickcode.in/

Ufa88kh said...

I am happy to visit your blog, a lot of things I can take the benefits of each of your articles. thank you
wordpress
ufa88kh.blogspot
youtube
casino online in cambodia

tech science said...


Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!data analytics course in nagpur

tech science said...



I feel very grateful that I read this. It is very helpful and very informative and I really learned a lot from it.<a href="https://360digitmg.com/india/cloud-computing-course-in-jaipur>cloud computing course in jaipur</a>

business analytics course in chennai with placement said...

I am looking for and I love to post a comment that "The content of your post is awesome" Great work! Business Analytics Course in Vadodara

subham kumar said...

thanks for sharing nice article visit Best Java Programming Tutorials and Courses

Dev Kumar said...


Really, this article is truly one of the best in the article. And this one that I found quite fascinating and should be part of my collection. Very good work!.
Data Science Training in Jaipur

Unknown said...
This comment has been removed by the author.
ODESSA said...

I appreciate you giving such lovely content. I learned something from your blog. Continue sharing.
lawyers for bankruptcy near me

naresh said...

Hi.

Thank you for sharing this information with us. This blog was great thanks for giving this information about c language and it uses and we learn some new things in this blog thanks for Sharing this information with us

Here is sharing some Oracle Project Accounting information may be its helpful to you.

Oracle Project Accounting Training

SHIVAM SHARMA said...

informative blog, your blog help me alot to undrestand this things in easy way, i too have some informative article here reactjs classes in pune

murugesan openssl said...

Adding my comment at ones complement + 1
binary number of 2 is:
10
||__ 0 * 2^0 = 0
|___ 1 * 2^1 = 2
0 + 2 = 2
Hence binary number of 2 is 10
Binary number of -2 is
ones complement of 2 + 1
Hence
01)
a = a + b
can be written using:
a = a - ( -b )
a = a - ( ones complement of b + 1 )
a = a - ones complement of b - 1
a = a - ~b - 1
b)
b = a - b
b = a + ( -b )
b = a + (ones complement of b + 1)
b = a + ~b + 1
c)
a = a - b
a = a + ( -b )
a = a + (ones complement of b + 1)
a = a + ~b + 1
It is better to describe above description at interview questions instead of describing and mugging ~b/~a...

«Oldest ‹Older   201 – 230 of 230   Newer› Newest»