Question Set

1. Will the following code work? #include<stdio.h> #include<malloc.h> struct emp { int len; char name[1]; }; int main() { char newname[] = "Rahul"; struct emp p = (struct emp ) malloc(sizeof(struct emp) -1 + strlen(newname)+1); p->len = strlen(newname); strcpy(p -> name, newname); printf("%d %s\n", p->len, p->name); return 0; }



Ask Your Doubts Here

Type in
(Press Ctrl+g to toggle between English and the chosen language)

Comments

  • By: guest on 01 Jun 2017 06.02 pm
    The program allocates space for the structure with the size adjusted so that the name field can hold the requested name.
Show Similar Question And Answers
QA->P and Q can do a work in 30 days. Q and R can do the same work in 24 days and R and P in 20 days. They started the work together, but Q and R left after 10 days. How many days more will P take to finish the work?....
QA->P and Q can complete a work in 15 days and 10 days respectively. They started the work together and then Q left after 2 days. P alone completed the remaining work. The work was finished in --- days.....
QA->A can complete a work in 12 days with a working of 8 hours per day. B can complete the same work in 8 days when working 10 hours a day. If A and B work together, working 8 hours a day, the work can be completed in --days.....
QA->P and Q can complete a work in 20 days and 12 days respectively. P alone started the work and Q joined him after 4 days till the completion of the work. How long did the work last?....
QA->P can do a work in the same time in which Q and R together can do it. If P and Q work together, the work can be completed in 10 days. R alone needs 50 days to complete the same work. then Q alone can do it in....
MCQ->Will the following code work? #include<stdio.h> #include<malloc.h> struct emp { int len; char name[1]; }; int main() { char newname[] = "Rahul"; struct emp p = (struct emp ) malloc(sizeof(struct emp) -1 + strlen(newname)+1); p->len = strlen(newname); strcpy(p -> name, newname); printf("%d %s\n", p->len, p->name); return 0; }....
MCQ->What will be the output of the program? #include<stdio.h> #include<stdarg.h> void fun1(char, int, int , float , char ); void fun2(char ch, ...); void (p1)(char, int, int , float , char ); void (p2)(char ch, ...); int main() { char ch='A'; int i=10; float f=3.14; char p="Hello"; p1=fun1; p2=fun2; (p1)(ch, i, &i, &f, p); (p2)(ch, i, &i, &f, p); return 0; } void fun1(char ch, int i, int pi, float pf, char p) { printf("%c %d %d %f %s \n", ch, i, pi, pf, p); } void fun2(char ch, ...) { int i, pi; float pf; char p; va_list list; printf("%c ", ch); va_start(list, ch); i = va_arg(list, int); printf("%d ", i); pi = va_arg(list, int); printf("%d ", pi); pf = va_arg(list, float); printf("%f ", pf); p = va_arg(list, char ); printf("%s", p); }....
MCQ->What will be the output of the program in 16-bit platform (under DOS)? #include<stdio.h> 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)); printf("%d, %d\n", sizeof(p), sizeof(q)); return 0; }....
MCQ->Which of the following is the correct way to define a variable of the type struct Emp declared below? struct Emp { private String name; private int age; private Single sal; } Emp e(); e = new Emp(); Emp e = new Emp; Emp e; e = new Emp; Emp e = new Emp(); Emp e;....
MCQ->Point out the error in the program? #include<stdio.h> #include<string.h> void modify(struct emp); struct emp { char name[20]; int age; }; int main() { struct emp e = {"Sanjay", 35}; modify(&e); printf("%s %d", e.name, e.age); return 0; } void modify(struct emp p) { p ->age=p->age+2; }....
Terms And Service:We do not guarantee the accuracy of available data ..We Provide Information On Public Data.. Please consult an expert before using this data for commercial or personal use | Powered By:Omega Web Solutions
© 2002-2017 Omega Education PVT LTD...Privacy | Terms And Conditions
Question ANSWER With Solution