[A]



[A] What will be the output of the following programs:

(1) #include

int main( )

{

struct employee

{

char name[25] ;

int age ;

float bs ;

} ;

struct employee e ;

e.name = “Hacker” ;

e.age = 25 ;

printf(‘%s %d\n”, e.name, e.age ) ;

return 0 ;

}

(2) #include

int main( )

{

char name[25] ;

char language[10] ;

} a ;

static struct a = { “Hacker”, “C” } ;

printf(“%s %s\n”, a.name, a. language ) ;

return 0 ;

}

(3) #include

struct virus

{

char signature[25] ;

int size ;

} v[2] ;

int main( )

{

static struct v[0] = {“Yankee Doodle”, 1813 } ;

static struct v[1] = {“Dark Avengar”, 1795} ;

int I ;

for (I = 0 ; I < =1 ; i++ )

printf(“%s %d\n”, v[i].signature, v[i].size ) ;

return 0 ;

}

(4) #include

struct s

{

char ch ;

int I ;

float a ;

} ;

void f (struct v) ;

void g (struct s * ) ;

int main( )

{

static struct s var = {‘C’, 100, 12.55 } ;

f (var) ;

g (&var) ;

return 0 ;

}

void f (struct s v )

{

printf (%c %d %f\n”, v->ch, v->I, v->a ) ;

void g (struct s *v)

{

printf(“%c %d %f\n”, v.ch, v.i, v.a ) ;

}

(5) #include

#include

int main( )

{

static char str1[] = “Ransacked” ;

char str2[20] ;

struct word

{

char str[20] ;

} ;

static struct word s1 ={“Ransacked” } ;

struct word s2 ;

strcpy (str2, str1 ) ;

s2 = s1 ;

printf(“%s %s\n”, s1.str, s2.str ) ;

printf(“%s %s\n”, str1, str2 ) ;

return 0 ;

(6) #include

#include

int main( )

{

struct

{

int num ;

float f ;

char mess[50] ;

} m ;

m.num = 1 ;

m.f = 3.14f ;

strcpy(m.mess, “Everything looks rosy” ) ;

printf(“%d %d %d\n”, &m.num, &m.f,m.mess) ;

printf (“%d %f %s\n”, m.num, m.f, m.mess) ;

return 0 ;

}

(7) #include

int main( )

{

static struct emp

{

char name[20] ;

int age ;

struct address

{

char city[20] ;

long int pin ;

}a ;

} e = {“abhijeet”, 30, “nagpur”, 440010) ;

printf(“%s %s\n”, e.name, e.a.city ) ;

return 0 ;

}

(8) #include

int main( )

{

struct a

{

char arr[10] ;

int I ;

float b ;

} v[2] ;

/*assume that first structure begins at address 1004*/

printf (“%d %d %d\n”, v[0]. Arr, &v[0].i, &v[0].b ) ;

printf(“%d %d %d\n”, v[1].arr, &v[1].i, &v[1].b) ;

return 0 ;

}

(9) #include

int main( )

{

struct a

{

char ch[7] ;

char*str ;

} ;

static struct a s1 = {“Nagpur”, “Bombay” } ;

printf( “%c %c\n”, s1.ch[0], *s1.str) ;

printf(“%s %s\n”, s1.ch, s1.str ) ;

return 0 ;

}

(10) #include

int main( )

{

struct a

{

char ch[7] ;

char*str ;

} ;

struct b

{

char *c ;

struct a ss1 ;

};

static struct b s2 = {“Raipur”, “Kanpur”, “jaipur” } ;

printf (“%s %s\n”, s2.c, s2.ss1.str ) ;

printf(“%s %s\n”, ++s2.c, ++s2.ss1.str) ;

return 0 ;

}

(11) #include

int main( )

{

struct s1

{

char*z ;

int I ;

struct s1 *p ;

} ;

static struct s1 a[] = {

{“Nagpur” , 1, a+1 },

{“Raipur”, 2, a+2 },

{“Kanpur”, 3, a}

} ;

static s1*ptr = a ;

printf(“%s %s %s\n”, a[0].z ptr->z, a[2].p->z ) ;

return 0 ;

}

(12) #include

int main( )

{

struct s1

{

char *str ;

int I ;

struct s1*ptr ;

} ;

static struct s1 a[] = {

{“Nagpur”, 1, a+1},

{“Raipur”, 2, a+2 } ,

{“Kanpur”, 3,a}

} ;

struct s1 *p = a ;

int j ;

for (j = 0 ; < = 2 ; j++ )

{

printf(“%d”, --a[i].i) ;

printf(“%s\n”, ++a[i].str) ;

}

return 0 ;

}

(13) #include

int main( )

{

struct s1

{

char *z ;

int I ;

struct s1*p ;

} ;

static struct s1 a[] = {

{ “Nagpur”, 1, a+1},

{“Raipur”, 2, a+2},

{“Kanpur”,3,a}

} ;

struct s1*ptr = a ;

printf(“%s\n”, ++(ptr->z) ) ;

printf(%s\n”, a[(++ptr)->i].z) ;

printf (“%s\n”, a[--(ptr->p->i)].z) ;

return 0 ;

}

(14) #include

int main( )

{

struct s1

{

char *str ;

struct s1 *ptr ;

} ;

static struct s1 arr[ ] = {

{“Nikhil”, arr+1},

{Aditya”, arr+2},

{Sudheer”, arr}

} ;

struct s1*p[3] ;

int I ;

for(I = 0 ; str ) ;

printf(“%s\n”, (**p)) ;

return 0 ;

}

(15) #include

struct s1

{

char *str ;

struct s1 *next ;

} ;

void swap (struct s1*, struct s1* ) ;

int main( )

{

static struct s1 arr[ ]= {

{“Akhil”, arr +1},

{“Nikhil”, arr+2},

{“Anant”, arr}

} ;

struct s1 *p[3] ;

int I ;

for ( I = 0 ; str, (*p)->str, (**p).str) ;

swap (*p, arr) ;

printf( “%s\n”, p[0]->str) ;

printf(“%s\n”, (*p) ->str) ;

printf(“%s\n, (*p)->next->str) ;

swap(p[0], p[0]->next->str) ;

printf(“%s\n”, p[0]->str) ;

printf (“%s\n”, (*++[0].str) ;

printf(“%s\n”, ++(*++(*p)-> next ).str) ;

return 0 ;

}

void swap (struct s1 *p1, struct s1*p2)

{

char *temp ;

temp = p1->str ;

p1->str = p2->str ;

p2->str = temp ;

}

(16) #include

#include

int main( )

{

struct node

{

int data ;

struct node *link ;

} ;

struct node *p, *q ;

p = ( struct node * ) malloc (sizeof (struct node) ) ;

q = (struct node *) (sizeof (struct node ) ) ;

printf (“%d %d\n”, sizeof(p), sizeof (q) ) ;

return 0 ;

}

(17 ) #include

#include

#define NULL 0

int main( )

{

struct node

{

int data ;

struct node *link ;

} ;

struct node*p, *q ;

p = ( struct node* ) malloc (sizeof (struct node) ) ;

q = (struct node* ) malloc (sizeof (struct node ) ) ;

p->data = 30 ;

p->link = q ;

q->data = 40 ;

q->link = NULL ;

printf(“%d\n”, p->data ) ;

p = p->link ;

printf (“%d\n”, p->data ) ;

return 0 ;

}

(18) #include

#include

#define NULL 0

int main( )

{

struct node

{

struct node *previous ;

int data ;

struct node *next ;

} ;

struct node*p,*q ;

p = (struct node *) malloc(sizeof (struct node ) ) ;

q = (struct node * ) malloc (sizeof (struct node) ) ;

p->data = 75 ;

q->data = 90 ;

p->previous = NULL ;

p->next = q ;

q->previous = p ;

q->next = NULL;

while (p != NULL)

{

printf(“%d\n”,p->data ) ;

p = p->next ;

}

return 0 ;

}

(19) #include

#include

#define NULL0

int main( )

{

struct node

{

int data ;

struct node *next;

} ;

struct node *p, *q ;

p = (struct node *) malloc (sizeof (struct node ) ) ;

q = (struct node * ) malloc (sizeof(struct node ) ) ;

p->data = 10 ;

q->data = 20 ;

p->next = q ;

q->next = p ;

while (p != NULL)

{

printf (“%d\n”, p-> data ) ;

p = p-> next ;

}

return 0 ;

}

(20) #include

int main ( )

{

struct a

{

int ;

char ch[4] ;

} ;

union b

{

int j ;

char c[4] ;

} ;

printf(“%d\n”, sizeof(struct a) ) ;

printf(“%d\n”,sizeof (union b ) ) ;

return 0 ;

}

(21) #include

int main( )

{

union a

{

int I ;

char ch[2] ;

} ;

union a u ;

u.i = 256 ;

printf( “%d %d %d\n”, u.i, u.ch[0],u.ch[1]) ;

return 0 ;

}

(22) #include

int main( )

{

struct a

{

long int I ;

char ch[4] ;

} ;

struct a s ;

s.i = 512 ;

printf (“%d %d %d\n”,s.ch[0], s.ch[1], s.ch[3]) ;

return 0 ;

}

(23) #include

int main( )

{

union a

{

int I ;

char ch[4] ;

} ;

union a u ;

u.ch[0] = 3 ;

u.ch[1] = 2 ;

u.ch[2] = 0 ;

u.ch[3] = 0 ;

printf (“%d %d %d\n”, u.ch[0],u.ch[1], u.i ) ;

return 0 ;

}

(24) #include

int main( )

{

struct a

{

int I ;

int j ;

} ;

struct b

{

char x[2] ;

char x[6] ;

} ;

union c

{

struct a aa ;

struct b bb ;

} ;

union c u ;

u. aa. I = 512 ;

u. aa. J = 512 ;

printf(“%d %d\n”, u.bb.x[0], u.bb.y[0]) ;

printf (“%d %d\n”, u.bb.y[1], u.bb.y[2]) ;

return 0 ;

}

(25) #include

int main( )

{

struct a

{

int I ;

int j ;

} ;

struct b

{

char x ;

char y ;

} ;

union c

{

struct a aa ;

struct b bb ;

} ;

union c u ;

} ;

u.aa.i = 256 ;

u.aa.j = 512 ;

printf (“%d %d\n” , u.aa. I, u.aa.j ) ;

printf(“%d %d\n”, u.bb.x, u.bb.y ) ;

return 0 ;

}

(26) #include

#include

int main( )

{

union

{

unsigned long l ;

unsigned short int d[2] ;

char ch [4] ;

} a ;

strcpy (a.ch, “ABC”) ;

printf(“%s\n”, a.ch) ;

printf(“%u %\n”, a.d[0],a.d[1]) ;

printf(“%u\n”,a.l) ;

return 0 ;

}

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download