Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

C Programming :: Dynamic Memory Allocation

Home > C Programming > Dynamic Memory Allocation > General Questions

1. What will print out?

#include
void main()
{
char *p1="name";
char *p2;
p2=(char*)malloc(20);
memset (p2, 0, 20);
while(*p2++ = *p1++);
printf("%s\n",p2);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

Tags:

BOA (Bank of America) 

2. What is the output of the following C Program?

#include
#include
void main()
{
int *mptr, *cptr;
mptr = (int*)malloc(sizeof(int));
printf("%d",*mptr);
cptr = (int*)calloc(sizeof(int),1);
printf("%d",*cptr);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

The memory space allocated by malloc is uninitialized,
whereas calloc returns the allocated memory space initialized to zeros.

Workspace

Tags:

No Tags on this question yet!

3. What is the output of the following 'C' program ?

#include
#include
#include
typedef struct
{
char *name;
} Addr;
int main()
{
Addr *s;
char comm[10];
char *str = "Hello";
s = (Addr *)malloc(sizeof(Addr));
printf("Enter a name");
fgets(comm, 10,stdin);
s->name = (char*)malloc(sizeof(char[strlen(comm)]));
strcpy(s->name, comm);
strcat(str,s->name);
printf("%s", str);
}

// for the input: india

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

4. What is the output of the following 'C' program ?

#define MAX 50
int fun1()
{
char *s1;
s1=(char *) malloc (MAX*sizeof(char));
s1="hello";
printf("%d",s1);
free(s1);
}
int fun2()
{
char *s;
s=(char *) malloc (MAX*sizeof(char));
strcpy(s,"hello");
printf("%d",s);
free(s);
}
int main ()
{
fun1();
fun2();
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

5. What will be the output of the program?

#include
#include

int main()
{
int *p;
p = (int *)malloc(20); /* Assume p has address of 1314 */
free(p);
printf("%u", p);
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

Tags:

Capgemini 

6. What is the output of the following 'C' program ?

#include
#include
int main()
{
int *p;
p = (int *)malloc(20);
printf("%d\n", sizeof(p));
free(p);
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

7. What is the output of the following C Program?

#include
#include
#define MAXROW 3
#define MAXCOL 4

int main()
{
int (*p)[MAXCOL];
p = (int (*) [MAXCOL])malloc(MAXROW *sizeof(*p));
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

8. What is the output of the program on a 32 bit Operating System?

#include
#include
void main () {
double val = 12.34;
double *dp = &val;
char *cp;
cp = (char*)malloc(sizeof(char) * 20);
sprintf (cp, "hello world");
printf("%d %d %d", sizeof(cp), sizeof(dp), sizeof(val));
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

Tags:

Commvault 

9. What is the output of the program?

#include
#include
void main()
{
char *pl= "word";
char *p2;
p2=(char*)malloc(10);

memset(p2, 'A', 10);
while(*p2++ = *pl++)
printf("%s ", p2);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

Tags:

Commvault 

10. What will be output of the following "c" code?

#include
#include
#include
void main()
{
char *p = "Hello";
char *q = "world";
int l1 = strlen (p);
int l2 = strlen (q);
char *l = (char*) malloc (sizeof (l1 + l2)+1);
while (*p) *l++ = *p++;
while (*q) *l++ = *q++;
*l = '\0';
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!