Technical Stuff

Q.1) Why array index start with 0?
Ans:-
             It starts at 0 because the index value tells the computer how far it needs to move away from the starting point in the array. If you use an array you are really only referring to the memory address of the starting point of the array. When you reference a specific value in the array, you are telling the programming language to start at the memory address of the beginning of the array and then move up the memory address as needed. So suppose a program allocates space in the memory between address numbers 1024 and 2048 and it starts at 1024 and each item in the array is 8 bytes long. Then saying arrayName[0] is the same as telling it to look at the data stored at the memory address of (1024 + (0 * 8)), or 1024. If you want the value stored at arrayName[1], then it looks at the value held at (1024 + (1*8)), which is 1032. If you wanted the value held at arrayName[10], then it would look at the data stored in the memory address of 1024 + (10 * 8), which is 1104.

Q.2)How to create header file in C?
Ans:-
        Create a file and save it as .h extension
      e.g.
           int add(int a,int b)
          {
              return(a+b);
          }
       Save as myheader.h
   
   In another program include this header file.

    e.g.
           #include<stdio.h>
           #include"myheader.h"
          void main()
         {
           int num1=10,num2=20,num3;
           num3=add(num1,num2);
            printf("Addition is =%d",num3);
          }


Q.3)Find maximum number without using conditional statements.
Ans:-
         1)By using max function in C
              Program
               
                       #include<stdio.h>
                       #include<stdlib.h>
                       void main()  
                       {
                           int a=10,b=20,c;
                            c=max(a,b);
                            printf("Max number is %d",c);
                       }

Q.4)What are the different approaches of programming?
Ans:-
        1)Object Oriented Programming
        2)Object Base Programming
        3)Procedure Oriented Programming
        4)Logical Programming
        5)Functional Programming
   
Q.5)Difference between while and for?
Ans:-
       While is dynamic and it is use when condition is not fixed.
       For is static and it is use when condition is fixed.

Q.6) Difference between if and switch?
Ans:-
            Switch
              The switch statement evaluates an expression, which must have an integral result. Based on that result, a branch is taken to one of the case statements, or to the default statement if present and none of the case statements match.
            If
               The if-else statement evaluates an expression, which must have a logical result. If the result is true, the first target statement executes - if false, the second target statement executes.


Q.7) why main is starting point of your program? Can it is possible to change?
    Ans:-
            It is defined in complier that it first search for main function. If it is not define it get confused from where to start. It is the entry point in program.
            It is possible to change name of main function like this –
                        #include<stdio.h>
                        #define abc main
                        void abc
                        {
                          printf(“\n hello”);
                        }

Q.8) File structure from c?
Ans:-
            typedef struct
 {
                short  level;
                unsigned flags;
                char fd;
                unsigned char  hold;
                short bsize;
                unsigned char *buffer, *curp;
                unsigned istemp;
                short token;
            } FILE;

Q.9) How to create array in C and C++?
Ans:-
            Array in C and C++ –
             Syntax -
                    data-type arrayname[size] ;
             e.g.
              int arr[10];//declaration;
              int arr[10]={1,2,3,4,5,6,7,8,9,10};// declaration and initialization

Q.10) what is the uses of { } in if?
Ans:-
            If we does not give the {} after if statement it execute only one statement after it. For execution of multiple statements under if condition we have to mention {} after if statement. If does not allowed declaration of variables, functions without {}.

Q.11) Program for 10 boxes?

Q.12) if we have array of integer which containing age for 10,000 people. Sort that array with       optimised way.
Ans:
            Program:-
                public class Sort
              {
                  static int a[]=new int[120];
                  public static void main(String[] args)
                 {
                      int age[]={10,15,17,20,10,13,12,15,15,40};
                      for(int i=0;i<age.length;i++)
                     {
                        int b=age[i];
                         a[b]=a[b]+1;       
                     }
                      for(int j=0;j<a.length;j++)
                     {
                       int r=a[j];
                         for(;r>0;r--)
                          {
                              System.out.println(j);
                          }
                     }
                 }
              }

Q.13)if you have 2 dice and you have to show date from 00-31
Ans:-
      Write on dice
         Dice 1-  0,1,2,3,4,5
         Dice 2-  0,1,2,6,7,8
      for displaying 9 rotate number 6.

Q.14) what can be parameter for switch?
Ans:
     Parameters for switch are Integer and character.
      1) Using Integer

          #include<stdio.h>
          void main()
          {
                int n;
                printf("\n enter choice");
                scanf("%d",&n);
                switch(n)
               {
                  case 1:
                            printf("\n You are in case 1");
                            break;
                  case 2:
                            printf("\n You are in case 2");
                            break;
                 default:
                            printf("\n You are in default case");
                            exit(0);
                  }
            }

     2)Using Character

            #include<stdio.h>
            void main()
            {
                   char c;
                   printf("\n enter choice");
                   scanf("%c",&c);
                   switch(c)
                   {
                        case 'A':
                                     printf("\n You are in case A");
                                     break;
                        case 'B':
                                     printf("\n You are in case B");
                                     break;
                       default:
                                     printf("\n You are in default case");
                                    exit(0);
                      }
                }


Q.15)if with demo.
Ans:-
        1)Declaration in condition
           #include<stdio.h>
           void main()
           {
              if(int a==10)        //Error Expression synatax
               printf("\n a");
           }
          It gives the expression syntax error

     2) Declaration in single line in if
           #include<stdio.h>
           void main()
          {
             int a=10;
              if(a==10)
                   int i;   //error - expression synatx
          }
  
        It gives the expression syntax error
   
       3)If with multiple condition

        #include<stdio.h>
        void main()
       {
          int a=10,b=20;
          if(a==10 && b==20)
          {
             int i;
             printf("\n a");
           }
       }

       Multiple conditions are allowed in if condition.

Q.16) for with demo.
Ans:-
            1) For loop without any initialization, condition and increment
                 #include<stdio.h>
                 void main()
                {
                     for(;;)
                     printf("\n hello");
                }
               It execute the printf statement inside for infinitely

           2)Initialization in for loop in C
               #include<stdio.h>
               void main()
              {
                    for(int i=0;i<5;i++)//error - expression syntax
                   {
                       printf("\n a");
                    }
               }
           It gives error expression syntax

         3)For loop with multiple initialization,conditions,increments in C
            #include<stdio.h>
           void main()
           {
                 int i,j;
                 for(i=0,j=0;i<5 && j<4;i++,j++)//Multiple initialization,condition,
                                                                 //increment,decrement is allowed
                  {
                      printf("\n a");//print 4 times a
                  }
           }
       Multiple initialization, conditions, increments/decrements is allowed in C

Q.17)while with demo
Ans:-
          1)While loop with multiple conditions
              #include<stdio.h>
              void main()
            {
                  int i=10,j=5;
                  while(i<10 && j<5)   
                 {
                     printf("\n while");
                      i++;
          j++;
                 }
          }
         multiple conditions are allowed in while.

        2)Initialization in while
            #include<stdio.h>
            void main()
          {

               while(int i<10 ) //error expression syntax
              {
                     printf("\n while");
              }
           }
    It gives error expression syntax

      3)single line declaration under while
          #include<stdio.h>
          void main()
         {
            int i=10;
            while(i<10)
                int a;//expression syntax
          }
       It gives error expression syntax.

Q.18) if we have array of 30m int sort with optimise way
      Condition for that-
        1) You cannot declare another array
        2) You cannot modify original array
        3) You cannot declare more than 5 variables
Q.19) how to change JVM's memory
          1) On cmd
          2) On eclipse
Q.20) what are the different algorithm available for garbage collection?
Q.21) You are working on critical mission project, as a part of the project,it is required to write a function in c which accept two co-ordinates(x1,y1) for a given point p, you need to determine which quadrant given point belongs, e.g. (10,15)(both are positive hence it in Quadrant I,where as point(-10,15) in Quadrant II. In all the there are nine possibilities as given below:
I Quadrant,II Quadrant,III Quadrant, IV Quadrant, +X Axis, -ve X Axis, +Y Axis, -Y Axis and Origin(0,0).




Unfortunately compiler on your computer has developed strange behaviour, it can't compile any conditional statements like If........then else,switch.....case, therefore you can't write any conditional statement. It is very urgent that we need to write the function and can't wait for your compiler to get fixed. Write program /function in c or VB which will accept 2 co-ordinates and return one of the 9 possible values given above. Please remember that you can't write any conditional statement in your function/program.
22) Difference between smart phone and feature phone

No comments:

Post a Comment