Find the output of following C program
1. #include<stdio.h>
int
main()
{
struct
A
{
int age;
char *name;
}A1;
struct
A B1;
A1.age=22;
A1.name="sachi";
printf("Age=%d\t",A1.age);
printf("Name=%s\n",A1.name);
B1
= A1;
printf("Age=%d\t",B1.age);
printf("Name=%s\n",B1.name);
return
0;
}
2. #include<stdio.h>
int
main()
{
struct
data
{
int age=22;
char *name="sachi";
}*ptr;
printf("%s\t",ptr->name);
printf("%d\n",ptr->age)
;
return
0;
}
3. #include<stdio.h>
int
main()
{
struct
data
{
int
age;
char *name;
}*ptr;
char
name1[10] ="Soumya";
ptr->name=name1;
ptr->age=39;
printf("%s\t",ptr->name);
printf("%d\n",ptr->age);
return
0;
}
4. #include<stdio.h>
int
main()
{
struct
data
{
int age;
char *name;
}var;
struct
data *ptr=&var;
char
name1[10] ="sachi";
ptr->name=name1;
ptr->age=22;
printf("%s\t",ptr->name);
printf("%d\n",ptr->age);
return
0;
}
5. #include<stdio.h>
struct
student
{
char name[20]; int age;
};
int
main()
{
struct
student stu1={"Arati",21},stu2={"Arati",20};
if(stu1==stu2)
printf("Same\n");
else
printf("Not
same\n");
return
0;
}
6. #include<stdio.h>
void
func (struct tag v);
int
main()
{
struct
tag
{
int
i; char c;
};
struct
tag var= {2,'s'};
func(var);
return
0;
}
void
func(struct tag v)
{
printr("%d %c\n",v.i,v.c);
}
7. #include<stdio.h>
struct
tag
{
int i; char c;
};
void
func(struct tag v )
{
printf("%d %c\n",v.i,v.c);
}
int
main()
{
struct tag var={2,'s'};
func(var);
return 0;
}
8. #include<stdio.h>
struct
tag
{int i; char c;};
void
func(struct tag);
int
main()
{
struct
tag var={12,'c'};
func(var)
;
printf("%d\n",var.i);
return
0;
}
void
func(struct tag var)
{
var.i++;
}
9. #include<stdio.h>
struct
tag
{int
i; char c;};
void
func (struct tag *);
int
main()
{
struct
tag var={12,'c'};
func(&var)
;
printf("%d\n",var.i);
return
0;
}
void
func (struct tag *ptr)
{
ptr->i++;
}
10.#include<stdio.h>
#include<string.h>
int
main()
{
union
tag
{
char name [15] ; int age;
}rec;
strcpy(rec.name,
"sss");
rec.age=23;
printf
("Name-%s",rec.name);
return
0;
}
11.#include<stdio.h>
struct
{
char
a[20];int b;
union
{
double c;
float d;
}y;
}z;
int
main()
{
printf ("%u
%u\n",sizeof(z.y),sizeof(z));
return 0;
}
12.#include<stdio.h>
int
main()
{
typedef
short int s_int;
unsigned
s_int var=3;
printf("%u",var);
return
0;
}
13.#include<stdio.h>
typedef
struct tag
{
int i; char c; }tag;
int
main()
{
struct
tag v1={1,'a'};
printf("%d
%c\n",v1.i,v1.c);
return
0;
}
14. #include<stdio.h>
typedef
struct
{ char name[20]; int age;}stu;
typedef
struct
{ int date; node *link;}node;
int
main()
{
stu
*p=malloc(sizeof(stu));
node
*ptr=malloc(sizeof(node));
p->age=30;
ptr->data=3;
printf("
%d %d\n",p->age,ptr->data);
return
0;
}
ANSWER
1. Age=22 Name=sachi
Age=22 Name=sachi
2. Ans-compilation error
3. Ans-Run time error
4. Ans-sachi 22
5. Ans-compilation error
6. Ans-compilation error
7. Ans-2 s
8. Ans-12
9. Ans-13
10. Ans-Name-Garbage value
11. Ans -8 32
12. Ans-compilation error
13. Ans-1 a
14. Ans-compilation error
No comments:
Post a Comment
For any doubt or suggestion you can write here