1. Question:What is pointer to a function? 

    Answer
    (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;<br />}
    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.

    1. Report
  2. Question: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;
    }

    1. Report
  3. Question: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)

    1. Report
  4. Question:What is difference between pass by value and pass by reference? 

    Answer
    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;<br />} 
    void swap(int *a,int *b){
        int  *temp;
        *temp =*a;
        *a=*b;
        *b=*temp;
    }
    Output: 10 5

    1. Report
  5. Question: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.

    1. Report
  6. Question:What is difference between uninitialized pointer and null pointer? 

    Answer
    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)

    1. Report
  7. Question: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

    1. Report
  8. Question: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.<br />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.

    1. Report
  9. Question:Write a c program to display mouse pointer? 

    Answer
    #include <dos.h>
    #include <stdio.h>
    void main()
    {
    union REGS i,o;
    i.x.ax=1;
    int86(0x33,&i,&o);
    getch();
    }

    1. Report
  10. Question:Write the c program to switch the 256 color graphics mode 

    Answer
    #include<stdio.h>
    #include<dos.h>
    void main()
    {
       int x,y,b;
       union REGS i,o;
       i.h.ah=0;
       i.h.al=0x13;
       int86(0x10,&i,&o);  
       getch();
    }

    1. Report
Copyright © 2024. Powered by Intellect Software Ltd