Interview Questions | Embedded | Interview Questions



Get "Embedded" Category

Subcategories

Sort by:

What is function overloading and operator overloading?

Function overloading: C++ enables several functions of the same name to be defined, as long as
these functions have different sets of parameters (at least as far as their types are concerned). This
capability is called function overloading. When an overloaded function is called, the C++ compiler
selects the proper function by examining the number, types and order of the arguments in the call.
Function overloading is commonly used to create several functions of the same name that perform
similar tasks but on different data types.

Read more on What is function overloading and operator overloading?…

What are the Side Effects of Shared-Memory Partition Options?

Shared-memory partitions have a separate create routine, memPartSmCreate( ), that returns a MEM_PART_ID. After a user-defined shared-memory partition is created, routines in memPartLib operate on it transparently. Note that the address of the shared-memory area passed to memPartSmCreate( ) (or memPartAddToPool( )) must be the global address.

Read more on What are the Side Effects of Shared-Memory Partition Options?…

What is POSIX-TIMER ?

The POSIX timer facility provides routines for tasks to signal themselves at some time in the future. Routines are provided to create, set, and delete a timer.
/* This example creates a new timer and stores it in timerid. */
/* includes */
#include “vxWorks.h”
#include “time.h”
int createTimer (void)
{
timer_t timerid;
/* create timer */
if (timer_create (CLOCK_REALTIME, NULL, &timerid) == ERROR)
{
 printf (“create FAILED\n”);
 return (ERROR);
}
return (OK);
}
An additional POSIX function, nanosleep( ), provides specification of sleep or delay time in units of seconds and nanoseconds, in contrast to the ticks used by the Wind taskDelay( ) function. Nevertheless, the precision of both is the same, and is determined by the system clock rate. Only the units differ.

Read more on What is POSIX-TIMER ?…

Write a program to implement user defined Macro instead of sizeof operator to find size of a data type

#include <stdio.h>
#define my_sizeof(X) (char*)((X*)10+1) – (char*)((X*) 10)
 
int main()
{
  int size;
     
  size =  my_sizeof(long);
 
  printf(“size=%d\n”,size);
 
  return 0;     
}

How do you write a program using c/c++ to configure maximum contiguous sum in an array?

Let us consider an array of integers, both positive and negative. we have to find out the maximum sum possible by adding ˜n consecutive integers in the array,

i.e. n <= [ARRAY_SIZE].

Read more on How do you write a program using c/c++ to configure maximum contiguous sum in an array?…

What is the difference between an object and a class?

Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.

  • A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don’t change.

Read more on What is the difference between an object and a class?…

Can bit fields be used on other data types than integer?

Ans: Bit fields can be specified only with integers (but when used on chars, it does not throw any warning or error!

Below are examples of structure with bit fields, highlighting different points.

Example-1:

struct bitFields {
int x : 16;
int y : 14;
int z : 2;
} bf1;

Read more on Can bit fields be used on other data types than integer?…

write a program to perform binary search using C

void main()
{
int a[10],i,n,m,c,l,u;
clrscr();
printf(“Enter the size of an array->”);
scanf(“%d”,&n);
printf(“\nEnter the elements of the array->”);
for(i=0;i”);
for(i=0;i”);
scanf(“%d”,&m);
l=0,u=n-1;
c=binary(a,n,m,l,u);
if(c==0)
printf(“\nThe number is not in the list”);
else
printf(“\nThe number is found”);
getch();
}
int binary(int a[],int n,int m,int l,int u)
{
int mid,c=0;
if(l<=u)
  {
    mid=(l+u)/2;
    if(m==a[mid])
     {
        c=1;
    }
else
 if(m<a[mid])
 {
   return binary(a,n,m,l,mid-1);
  }
  else
   return binary(a,n,m,mid+1,u);
  }
  else
  return c;
 }

Read more on write a program to perform binary search using C…

write a program in C to find – a number is prime or not

void main()
{
  int num,i,count=0;
  clrscr();
  printf(“\nEnter a number:”);
  scanf(“%d”,&num);
  for(i=1;i<=num;i++)
  {
    if(num%i==0)
    count++;
  }
  if(count==2)
    printf(“%d is a prime number”,num);
  else
    printf(“%d is not a prime number”,num);
  getch();
  }

Read more on write a program in C to find – a number is prime or not…

write a program in C to reverse a number

void main()
{
  int num,out;
  clrscr();
  scanf(“%d”,&num);
  out=rev(num);
  printf(“%d”,out);
  getch();
}
int rev(int num)
{
  static sum,r;
  if(num)
  {
    r=num%10;
    sum=sum*10+r;
    rev(num/10);
  }
  else return 0;
  return sum;
}

Read more on write a program in C to reverse a number…

How to initialize a SCSI Disk Drive in VxWorks?

This example initializes a SCSI disk as a single file system volume (and assumes that the disk is already formatted).

STATUS usrScsiDiskInit
(
int scsiId /* SCSI id */
)
{
int dcacheSize = 128 * 1024 ; /* 128KB disk cache */
char *diskDevName = “/sd0″ ; /* disk device name */
CBIO_DEV_ID cbio; /* pointer to a CBIO_DEV */
BLK_DEV *pBlk; /* pointer to a BLK_DEV */
SCSI_PHYS_DEV *pPhys ; /* pointer to a SCSI physical device */
/* Create the SCSI physical device */
if ((pPhys = scsiPhysDevCreate(pSysScsiCtrl, scsiId, 0, 0, NONE, 0,0, 0))== NULL)
{
 printErr (“usrScsiDiskInit: scsiPhysDevCreate SCSI ID %d failed.\n”,
 scsiId, 0, 0, 0, 0, 0);
 return ERROR;
}
/* Create the block device */
if( (pblk = scsiBlkDevCreate(pPhys, 0, NONE )) == NULL )
 return ERROR;
/*
* works for ids less than 10
* append SCSI id to make the device name unique
*/

diskDevName[strlen(diskDevName)-1] += scsiId ;
/* create disk cache */
if((cbio = dcacheDevCreate(pblk, NULL, dcacheSize, diskDevName)) == NULL )
 return ERROR ;
 /* create the file system, 10 simultaneously open files, with CHKDSK */
 dosFsDevCreate( diskDevName, cbio, 10, 0 );
 return OK;
}

Read more on How to initialize a SCSI Disk Drive in VxWorks?…

write a program to find out transpose of a matrix in C

void main()
{
int a[10][10],b[10][10],i,j,k=0,m,n;
clrscr();
printf(“\nEnter the row and column of matrix”);
scanf(“%d %d”,&m,&n);
printf(“\nEnter the First matrix->”);
for(i=0;i “);
for(i=0;i
 {
   printf(“\n”);
   for(j=0;j
   {
     printf(“%d\t”,b[i][j]);
   }
 }
getch();
}

Read more on write a program to find out transpose of a matrix in C…

What operations are allowed on an array ?

Please find the following points:
> Comparison of a string with pointer or base address is not allowed in C.
    We have to use string functions from string.h
 
   Following line is from K&R:
   There are no operations that manipulate an entire array or string although structures can be copied as a unit.
> sizeof operator will return number of bytes for a given variable/object/data type.
   Ex:
int main()
{
  int i,n;
  char str[]=”Hello”;
  int arr[]={1,2,3,4,5};
 

Read more on What operations are allowed on an array ?…

How to create or remove sub-directories in VxWorks ?

creation :
For FAT32, subdirectories can be created in any directory at any time. For FAT12 and FAT16, subdirectories can be created in any directory at any time, except in the root directory once it reaches its maximum entry count. Subdirectories can be created in the following ways:

Read more on How to create or remove sub-directories in VxWorks ?…

write a C program to convert decimal number to octal number

void main()
{
int i=0,j=0,rem=0,a[10],b[10];
long int num;
clrscr();
printf(“\nEnter a number :”);
scanf(“%ld”,&num);
while(num)
{
if(num<8) num=”num/8;” i=”j-1;i”>=0;i–)
 b[rem++]=a[i];
 printf(“\nOctal equivalent :”);
 for(j=0;j
 printf(“%d”,b[j]);
 getch();
}

Write a program to find out whether a number is armstrong number or not

What is an Armstrong number?

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.

Read more on Write a program to find out whether a number is armstrong number or not…

How to designate your own Stack for a pThread in Vx-Works?

pthread_attr_init(&attr);
/* allocate memory for a stack region for the thread */
stackbase = malloc(2 * 4096);
if (stackbase == NULL)
{
 printf(“FAILED: mystack: malloc failed\n”);
 exit(-1);
}
/* set the stack pointer to the base address */
stackptr = (void *)((int)stackbase);
/* explicitly set the stackaddr attribute */
pthread_attr_setstackaddr(&attr, stackptr);
/* set the stacksize attribute to 4096 */
pthread_attr_setstacksize(&attr, (4096));
/* set the schedpolicy attribute to SCHED_FIFO */
pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
/* create the pthread */
ret = pthread_create(&tid, &attr, mystack_thread, 0);

Read more on How to designate your own Stack for a pThread in Vx-Works?…

What is the difference between class and structure?

Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public.

Read more on What is the difference between class and structure?…

What is the difference between realloc() and free()?

The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will occur. The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is not a valid pointer.

Read more on What is the difference between realloc() and free()?…

What is virtual constructors/destructors?

Virtual destructors: If an object (with a non-virtual destructor) is destroyed explicitly by applying
the delete operator to a base-class pointer to the object, the base-class destructor function
(matching the pointer type) is called on the object.
There is a simple solution to this problem “ declare a virtual base-class destructor. This makes all
derived-class destructors virtual even though they dont have the same name as the base-class
destructor. Now, if the object in the hierarchy is destroyed explicitly by applying the delete operator
to a base-class pointer to a derived-class object, the destructor for the appropriate class is called.

Read more on What is virtual constructors/destructors?…