Tuesday, 4 March 2014

programming solutions: SORTING programms

programming solutions: SORTING programms: //BUBBLE SORT USING C PROGRAM #include<stdio.h> int main(){   int s,temp,i,j,a[20];   printf("Enter total numbers of elem...

programming solutions: 10:ARRAY programms

programming solutions: 10:ARRAY programms: // FIND OUT LARGEST NUMBER IN AN ARRAY USING C PROGRAM #include<stdio.h> int main(){   int a[50],size,i,big;   printf("\nE...

programming solutions: Area and volume

programming solutions: Area and volume: //C PROGRAM TO CALCULATE AREA OF A CIRCLE #include <stdio.h> #define PI 3.141 int main(){   float r, a;   printf("Radius:...

programming solutions: Very large numbers

programming solutions: Very large numbers: //Multiplication of large numbers in c #include<stdio.h> #include<math.h> #include<stdlib.h> #include<string.h&g...

programming solutions: Others programs

programming solutions: Others programs: //C program for ATM transactions #include<stdio.h> int totalThousand =1000; int totalFiveFundred =1000; int totalOneHundred =1...

programming solutions: how goto use stament

programming solutions: how goto use stament: what is goto stament in c? how use goto in programm #include<stdio.> #include<conio.h> // who Linux user pleseRemove this i...

Saturday, 1 February 2014

Arrays questions

(1) What will be output when you will execute the following program?

#include<stdio.h>
union A{
char p;
float const * const q;
};
int main(){
    union A arr[10];
    printf("%d",sizeof arr);
   return 0;      
}
  
Output: 20
(2) What will be output when you will execute the following program?
#include<stdio.h>
union A{
    char character;
    int ascii;
};
int main(){
    union A arr[2]={{65},{'a'}};
    printf("%c %c",arr[0],arr[1]);
       return 0;      
}
  
Output: A a
(d) Array of structure
 An array which can hold address of structure data type is known as array of structure. For example:
(1) What will be output when you will execute the following program?

#include<stdio.h>
typedef struct stu{
    char * name;
    int roll;
}s;
int main(){
    s arr[2]={{"raja",10},{"rani",11}};
    printf("%s %d",arr[0]);
    return 0;        
}
Output: raja 10
(3) What will be output when you will execute the following program?

#include<stdio.h>
struct A{
    int p;
    float q;
    long double *r;
};
int main(){
    struct A arr[10];
    printf("%d",sizeof arr);
   
    return 0;        
}
Output: 80
(e) Array of string
    An array which can hold integer data type is known as array of integer.
(f) Array of array
    An array which can hold address of another array is known as array of array.
(g) Array of address of integer
    An array which can hold address integer data type is known as array of address of integer.
Pointer to array

A pointer which holds base address of an array or address of any element of an array is known as pointer to array. For example:
(a)

#include<stdio.h>
int main(){
    int arr[5]={100,200,300};
    int *ptr1=arr;
    char *ptr2=(char *)arr;
    printf("%d   %d",*(ptr1+2),*(ptr2+4));

       return 0;       
}
Output: 300   44

(b)

#include<stdio.h>
int main(){
    static int a=11,b=22,c=33;
    int * arr[5]={&a,&b,&c};
    int const * const *ptr=&arr[1];
    --ptr;
    printf("%d ",**ptr);
        return 0;        
}
Output: 11
#include<stdio.h>
int main(){
    int arr[3]={10,20,30};
    int x=0;
    x = ++arr[++x] + ++x + arr[--x];
    printf("%d ",x);
    return 0;
}
Output: 44
#include<stdio.h>
int main(){
    int a[]={10,20,30,40};
    int i=3,x;
    x=1*a[--i]+2*a[--i]+3*a[--i];
    printf("%d",x);
    return 0;
}
Output: 100
#include<stdio.h>
int main(){
    static int a[][2][3]={0,1,2,3,4,5,6,7,8,9,10,11,12};
    int i=-1;
    int d;
    d=a[i++][++i][++i];
    printf("%d",d);
    return 0;
}
Output: 10

#include<stdio.h>
int main(){
    static double *p,*q,*r,*s,t=5.0;
    double **arr[]={&p,&q,&r,&s};
    int i;
    *p=*q=*r=*s=t;
    for(i=0;i<4;i++)
        printf("%.0f  ",**arr[i]);
    return 0;
}
output error