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
What is malloc in c++?
What is the most powerful coding language?
What is a container class?
What do you understand by zombie objects in c++?
Is c the same as c++?
How many different levels of pointers are there?
List the issue that the auto_ptr object handles?
Can we define a constructor as virtual in c++?
What is a buffer c++?
What are the differences between the function prototype and the function defi-nition?
What are the main features of c++?
How would you implement a substr() function that extracts a sub string from a given string?
What is the function of I/O library in C++ ?
Which one is better- macro or function?
Which is not an ANSII C++ function a) sin() b) tmpnam() c) kbhit()