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.


Please wait...

  Take Quiz (Monsoon) Beta Version !!
  Do You have Qs. in your Mind ??? Ask it as Qs. or MCQs or create it as polling Live Now !!

C Programming :: Dynamic Memory Allocation

Home > C Programming > Dynamic Memory Allocation > General Questions

1 / 18

 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);
}

Answer: Option B

Explanation:

In the given question expression while(*p2++ = *p1++); loop is evaluating the expression: *p2++ = *p1++. The while loop expression *p2 = *p1 is evaluated using the result of *p1. However, this value is still assigned to *p2 even if the expression evaluates as false or (0).


As in each step p1 and p2 address is incremented, when while loop terminated y that time p1 and p2 will point to null. so that when p2 printed blank printed. even p1 will too print blank (empty string)



Workspace

2 / 18

 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);
}

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 / 18

 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

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace


Tags:  No Tags on this question yet!

4 / 18

 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;
}

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace


Tags:  No Tags on this question yet!

5 / 18

 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;
}

Answer: Option A

Explanation:

the answer is 12157648 ie random values


Workspace


Tags:  Capgemini

6 / 18

 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;
}

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace


Tags:  No Tags on this question yet!

7 / 18

 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;
}

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace


Tags:  No Tags on this question yet!

8 / 18

 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));
}

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace


Tags:  Commvault

9 / 18

 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);
}

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace


Tags:  Commvault

10 / 18

 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';
}

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace


Tags:  No Tags on this question yet!