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
Can we use pointers in c++?
Why do we use double in c++?
What is runtime errors c++?
Is linux written in c or c++?
Tell me what are static member functions?
Describe protected access specifiers?
Why do we use string in c++?
Difference between a copy constructor and an assignment operator.
What does flush do?
What is a string example?
How much maximum can you allocate in a single call to malloc()?
Why should we use null or zero in a program?
How can I learn c++ easily?
Is swift faster than go?
What are the extraction and insertion operators in c++? Explain with examples.