1. Question:Write a c program to print Hello world without using any semicolon. 

    Answer
    Solution: 1
    void main(){
      if(printf("Hello world")){
      }
    }
    Solution: 2
    void main(){
        while(!printf("Hello world")){
       }
    }
    Solution: 3
    void main(){
       switch(printf("Hello world")) {
       }
    }

    1. Report
  2. Question:Swap two variables without using third variable. 

    Answer
    #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=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;
    }

    1. Report
  3. Question:What is dangling pointer in c? 

    Answer
    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 temporaryExplanation: 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

    1. Report
  4. Question:What is wild pointer in c? 

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

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

    1. Report
  6. Question:Do you know memory representation of  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 sidear type of data

    1. Report
  7. Question:What is and why array in c? 

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

    1. Report
  8. Question:Why we use do-while loop in c? Also tell any properties which you know? 

    Answer
    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

    1. Report
  9. Question:What is the meaning of prototype of a function? 

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

    1. Report
  10. Question:Write a c program to modify the constant variable in c? 

    Answer
    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

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