Saturday 21 November 2015

What is endianness of a processor Little endian and Big endian

        What is endianness of a processor Little endian and Big endian         


Endianness of a processor

If the size of data type is more than one byte then endanness decide the memory representation of data type. There are two types of microprocessor according to endianness.

Little-endian Format:
The processors which follow the following memory representation of data are known as little-endian processor.
little endian format


First A will fill then B then C then D then E and so on from right to left. Example of processor: 8085, 8086, 8088, 80286, 80386, p1, p2 etc.

Big-endian Format:
big endian format

The processors which follow the following memory representation of data are known as big-endian processor.
  
First A will fill then B then C then D then E from right to left. Example of processor: Motorola, IBM PC etc.

If you have any problem in what is endianness of a processor, you can ask here.

Thursday 19 November 2015

Write a c programming code to create simple paint brush software

      Write a c programming code to create simple paint brush software       


Write a c programming code to create simple paint brush software or application


#include<dos.h>
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int x,y,b,px,py,c,p,s,cl;
int d=0,m;
union REGS i,o;
initgraph(&d,&m,"c:\tc");
i.x.ax=1;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=20;
i.x.dx=450;
int86(0x33,&i,&o);
printf("Brush style insert number from 0 to 5  : ");
scanf("%d",&p);
printf("Brush size insert number from 1  to 7  : ");
scanf("%d",&s);
printf("Brush color insert number from 1 to 16 : ");
scanf("%d",&cl);
clrscr();
cleardevice();
printf("\t\t**********DRAW IMAGE************");
while(!kbhit())
{
i.x.ax=3;
b=o.x.bx;
x=o.x.cx;
y=o.x.dx;
px=x;
py=y;
int86(0x33,&i,&o);
if(cl==16)
{
c=random(16);
}
else
{
c=cl;
}
setcolor(c);
if(b==1)
{
i.x.ax=3;
int86(0x33,&i,&o);
x=o.x.cx;
y=o.x.dx;
b=o.x.bx;
switch(p)
{
case 1:circle(px,py,s);break;
case 2:ellipse(px,py,0,270,s,s+2);break;
case 3:fillellipse(px,py,s+2,s);break;
case 4:rectangle(px,py,x,y);break;
case 5:sector(px,py,30,120,s,s);break;
default:line(px,py,x,y);
}
}
}
getch();
restorecrtmode();
closegraph();
}

      Cursor program by c programming changes the position of cursor   

Write a c program which changes the position of cursor

#include<dos.h>
#include<stdio.h>
void main()
{
union REGS i,o;
i.h.ah=2;   //positioning the cursor 
i.h.bh=0;
i.h.dh=30;   
i.h.dl=45;
int86(0x10,&i,&o);
printf("World");
getch();
}


             Write a c program to display mouse pointer                  

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

Explanation: To write such program you must have one interrupt table. Following table is only small part of interrupt table.
This table consists for column. They are:
(1)   Input
(2)   Output
(3)   Service number
(4)   Purpose

Now look at the first row of interrupt table. To show the mouse pointer assign ax equal to 1 i.e. service number while ax is define in the WORDREGS

struct WORDREGS {
unsigned int ax, bx, cx, dx;
unsigned int si, di, cflag, flags;
};

And WORDRGS is define in the union REGS

union REGS {
struct WORDREGS x;
struct BYTEREGS h;
};

So to access the structure member ax first declare a variable of REGS i.e.

REGS i, o;
Note: We generally use i for input and o for output

To access the ax write i.x.ax (We are using structure variable i because ax is input
(See in the interrupt table)

So to show mouse pointer assign the value of service number to it:

i.x.ax=1;

To provide this information to microprocessor
we use int86 function. It has three parameters

1. Interrupt number i.e. 
0x33
2. union REGS *inputregiste i.e. &i
3. union REGS *outputregiste i.e. &o;
So write: int86 (0x33, &i, &o);

C Aptitude Questions For Placement Part-II


          C Aptitude Questions For Placement Part-II                    

1. What is the output of the following program?
void main()
{
     int a=2;
     switch(a) ;
     {
       case 1: printf(“A”);
       case 2: printf(“B”);
       case 3: printf(“C”); break;
       case 4: printf(“D”);
       default:printf(“E”); break;
     }  }
Ans:- Error


2.What is the output of the following program?
void main()
{
     int a=2;
     switch(a){
       case 1: printf(“A”);
               break;
       case 2: printf(“B”);
               continue;
       case 3: printf(“C”);
               break;
       case 4: printf(“D”);
       default:printf(“E”);
     }
  }
Ans:- Error


3.What is the output of the following program?
 void main()
{
     int a=2;
     switch(a)
{
       case4: printf(“A”);
               break;
       case3: printf(“B”);
       case2: printf(“C”);
       case1: printf(“D”);
              break;
       default:printf(“E”);
     }
  }
Ans:- E


4.What is the output of the following program?
void main()
{
        int a=2;
       switch(a)
{
       case 4: printf(“A”);
               break;
       case 3: printf(“B”);
       case default: printf(“C”);
       case 1: printf(“D”);
              break;
       case 5:printf(“E”);
       }
    }
Ans:- Error


5.What is the output of the following program?
void main()
{
     int a,b,c,d;
     a=b=c=d=1;
     a= ++b>1 || ++c>1 && ++d>1;
     printf(“%d %d %d %d”,a,b,c,d);
  }
Ans:- 1 2 1 1


6.What is the output of the following program?
void main()
{
     int a;     a=1;
     while(a<=10)
      {
        printf(“%d “,a);
        if(a>3)
         break;        a++;
       }    
     printf(“%d “,a+10);
 }
Ans:- 1 2 3 4 14


7.What is the output of the following program?
void main()
{
     int a;
     a=1;
     while(a<=10){
        printf(“%d “,a);
        if(a>3 &&a<8)
        continue;
        a++;
       }    
     printf(“%d “,a+10);
  }
Ans:- 1 2 3 4 4 4 4…


8.What is the output of the following program?
 void main()
  {
     int a=-1;
     printf(“%d %u %o %x”,a,a,a,a);
  }
Ans:- -1 65535  177777 ffff


9.What is the output of the following program?
void main()
{
     int a=100;
     printf(“%d %u %o %x”,a,a,a,a);
  }
Ans:- 100 100 0144 0X64


10.What is the output of the following program?
void main()
{
printf(“%d %d %d”,10<<1,10>>1,~10);
printf(“%d %d %d”,10^20,10|20,10&20);
  }
Ans:- 20 5 -11 30 30 0


11.What is the output of the following program?
void main()
{
     int a=1;
     a=a<<15;
     printf(“%d”,a);
  }
Ans:- -32768

12.What is the output of the following program?
void main()
{
     int a;
     a=453<<16;
     printf(“%d”,a);
  }
Ans:- 0


13.What is the output of the following program?
void main()
{
     int a;
     a=453>>16;
     printf(“%d”,a);
 }
Ans:- 0


14.What is the output of the following program?
void main()
{
     int a;
     a=~0;
     printf(“%d”,a);
  }
Ans:- -1


15.What is the output of the following program?
void main()
{
printf(“%d %d %d”,-10^9,-10|9,-10&9);
  }
Ans:- -1 -1 0


16.What is the output of the following program?
void main()
{
   int x=10,y=20;
   while(x++<=12||y++<=22)
   printf(“n%d %d”,x,y);
   printf(“%d %d”,x+10,y+10);
}
Ans:-   11 20
12 20
13 20
14 21
15 22
16 23
27 34


17.What is the output of the following program?
void main()
{
   float a;
   a=8.5;
    if( a==8.5)
    printf(“1”);
    else
    printf(“2”);
  } 
Ans:-  1


18.What is the output of the following program?
void main()
{
   int a;
   a= -1;
   while(a–);
   printf(“%d”,a);
 }
Ans:-   -1


19.What is the output of the following program?
void main()
{
   int i;
    i=1;
   i=i+2*i++;
   printf(“%d”,i);
}
Ans:- 4


21.What is the output of the following program?
main()
{
   int i=10;
   printf(“%d %d %d”,++i,i++,++i);
 }
Ans:- 13 11 11


22.What is the output of the following program?
main()
{
   int a=10,b=20;
   a>=5?b=100:b=200;
 printf(“%d”,b);
}
Ans:- 100


 23.What is the output of the following program?
int main()
{
       int x=10,y=20;
       if(!(!x)&&x)
       {
           printf(“x=%d”,x);
       }
       else
        {
          printf(“y=%d”,y);
         }
       return 0;
   }
Ans:- x=10


24.What is the output of the following program?
int main()
{
   int x,y,z;
   x=y=z=1;
   z=++x||++y&&z;
   printf(“%d %d %d”,x,y,z);
   return 0;
}
Ans:- 2 1 1