Interview Q and A 9

Interview Q and A 9



Ques 1. How to know the given controller is little endian or big endian ?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    unsigned int x=0xaa55;
    unsigned char *p=&x;
if(*p == 0x55)
{
    printf("\n Little endian");
    printf("%x = %x\n",p, *p);
    printf("%x = %x\n",(p+1),*(p+1));
}
else
    printf("\n Big endian");
    return 0;
}


Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a=5;
    {
      int a=9;
      printf("\n %d",a);
    }
    printf(" %d",a);
    return 0;
}

Ans. 9 5


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a=5;
    {
      a=9;
      printf("\n %d",a);
    }
    printf(" %d",a);
    return 0;
}

ans :  9 9



Ques 4. What is the difference between General purpose os and RTOS ?

RTOS :
  Rtos scheduling is based on priority
  Resopnse time is predictable
  kernel is preemptive or upto maximum degree
  priority inversion is a major issue
  it has less memory

Ex: Free RTOS, vxworks, RT linux, PSOS, VRTX, Lynx

General Purpose OS:
  GPOS scheduling  can be adjusted dynamically for optimized throuhput.
  Resopnse time is not predictable
  kernel is non preemptive or upto maximum degree
  priority inverson is unnoticed.
  it is having large memory.
 Ex: Microsoft windows, Redhat Linux, Apple MacOS


Ques 5. explain the meaning of below declaration?

const int PI, int const PI, const int *p,  int * const p, const int *const p;

const int PI : PI is a integer constant.
int const PI : PI is a integer constant.
const int *p:  p is a pointer to constant integer, data present in p is constant and ponter is not constant.
int * const p: pointer p is constant and data is not constant.
const int * const p: both pointer p and data are constant. 


Ques 6. what are the bitwise operators and its types?

bitwise operators are as mentioned below:

| bitwise or operator   
& bitwise and operator
~ bitwise 1's complement operator
^ bitwise xor operator
<< bitwise left shift operator
>> bitwise right shift operator.


Ques 7. which operator is suitable for checking perticular bit is set or not?
 >> and & operators.


Ques 8. what is the output for the below code?
int main()
{
    int a=3;
    int x=-15;

    a+x > 5? puts("a+x > 5 "): puts("a+x < 5");

    return 0;
}


ans: a+x < 5


Ques 9. write a program to swap two numbers without using third variable?

swap(int *p, int *q)
{
  *p=*p+*q;
  *q= *p-*q;
  *p=*p-*q;
}


Ques 10. write a program to pass array as argument to a function?

fun(int p[])
{
  int i=0;
  for(; i<3; i++)
  printf(" = %d \n", p[i]);

}

int main()
{
    int a[3] ={2,3,4};
    fun(a);
    return 0;
}


Ques 11. what is ohms law?
ohms law states that the current through the conductor is directly proportional to the voltage across
the two points of the conductor with resistance is constant.


Ques 12. what is the difference between call by value and call by reference ?
	call by value means we are passing copy of the original arguments to the formal arguments of the function.
             here the value changed in the formal arguments will not affect the original arguments 
	call by referece means we are passing the address of the arguments to the formal arguments of the function.
             here the value changed in the formal arguments will affect the original arguments.

Ques 13. what is the output for the below code if integer size is 4 bytes?

int main()
{
	int x=-1;
	printf("%x ", (x>>1));
	return 0;
}

ans : ffffffff


Ques 14. what is the equivalent pointer expression for the array element arr[i][j][k][m]?

ans:     *(*(*(*(arr+i)+j)+k)+m)


Ques 15. what is the output for the below code?

int main()
{
	int *p, **q, ***r;
	int x=9;
        p=&x;
	q=&p;
	r= &q;
	printf("%d %d %d", *p, **q, ***r);
	return 0;
}

ans: 9 9 9



Ques 16. what is the requirement of infinite loop in embedded system?

	Since embedded system has to continuously work and respond to the inputs, and some other jobs in loop. 
to make the system to run continuously for long time it has to be kept in infinite loop. 
Otherwise it will run only once and stops.



Ques 17: explain about ALU?
 ALU is present in the microprocessors  and microcontrollers. it will do the arithmetic and logic operations
 that is required to be done on instructions. The cpu is powerful if the design of the ALU good. It consumes
 more power and it releases more heat. This is why faster cpus consume more power releases more heat.