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 are the advantages of using a pointer?
Difference between a homogeneous and a heterogeneous container
Can we define function inside main in c++?
What is the use of namespace std in C++?
What is #include c++?
What is an object in c++?
Explain 'this' pointer and what would happen if a pointer is deleted twice?
why and when we can declar member fuction as a private in the class?
How long will it take to learn programming?
What is recursion?
Explain the difference between realloc() and free() in c++?
Write a recursive program to calculate factorial in c++.
Should a constructor be public or private?
What are single and multiple inheritances in c++?
Is c++ high level programming language?