1)#include <iostream.h>

int main()
{
int *a, *savea, i;

savea = a = (int *) malloc(4 * sizeof(int));

for (i=0; i<4; i++) *a++ = 10 * i;


for (i=0; i<4; i++) {
printf("%d\n", *savea);
savea += sizeof(int);
}
return 0;
}
2)#include <iostream.h>

int main()
{
int *a, *savea, i;

savea = a = (int *) malloc(4 * sizeof(int));

for (i=0; i<4; i++) *a++ = 10 * i;


for (i=0; i<4; i++) {
printf("%d\n", *savea);
savea ++;
}
return 0;
}
The output of this two programs will be different why?

Answer Posted / mahesh

first program prints sum of saved and size of int

second one prints only the contenst of saved

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Define basic type of variable used for a different condition in C++?

759


Difference between overloaded functions and overridden functions

681


Will this c++ program execute or not?

702


Keyword mean in declaration?

678


Can a constructor return a value?

676






What are c++ templates used for?

714


What is the difference between delegation and implemented-in-terms-of?

632


Is dev c++ free?

694


What is pure virtual function? Or what is abstract class?

682


What are c++ tokens?

693


What are enumerations?

746


On throwing an exception by the animal constructor in p = new animalq, can memory leak occur?

769


Explain how would you handle a situation where you cannot call the destructor of a local explicitly?

623


Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

706


Why do we learn c++?

622