Wednesday, 21 October 2015

Embedded C Programs for Interview - String

String Programs

Malloc to initialize array, to check nth count of array!!

int *a;
printf("enter the number of variables\n");
scanf("%d",&o);
printf("Variable is %d\n",o);
a=(int*)malloc(o*sizeof(int));
printf("Enter Elements of First List \n");
    for (i = 0; i < o; i++)    {
        scanf("%d", a + i);
    }
int s=sizeof(a)/sizeof(int);
printf("\n%d\t%u\n",s,&s);
for(m=0;m<=3;m++)
printf("%d\n",a[m]);



Program for sizeof data types


#include <stdio.h>
int main()
{
    printf("Size of data type for Char-%d!\n",sizeof(char));
    printf("Size of data type for Short-%d!\n",sizeof(short));
    printf("Size of data type for Int-%d!\n",sizeof(int));
    printf("Size of data type for Long-%d!\n",sizeof(long));
    printf("Size of data type for Double-%d!\n",sizeof(double));
    return 0;
}

Integer reverse program




#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,cnt=0,o,count=0,l=0,cnt1=0,j=0,k=0,m;
int *a;
char b[5];
printf("enter the number of variables\n");
scanf("%d",&o);
printf("Variable is %d\n",o);
a=(int*)malloc(o*sizeof(int));
printf("Enter Elements of First List \n");
    for (i = 0; i < o; i++)    {
        scanf("%d", a + i);
    }
printf("Reversed String is\n");
while(o!=0)
{
printf("%d\n",a[o-1]);
o--;
}
}

Pointer Initialization


#include <stdio.h>

int main()
{
    int a=9;
    int *p;
    *p=0x012;
     printf("%d\n%u\n%u\n",*p,p,&p);
    *p=a;
    printf("\n%d,%u\n",*p,&p);

    return 0;
}

String Reverse Program