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

Is c++ used anymore?

595


What is the use of setprecision in c++?

548


What is #include c++?

571


What is the use of "new" operator?

660


Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?

560






Is it possible for the objects to read and write themselves?

651


Explain binary search.

576


What is namespace std; and what is consists of?

668


Who created c++?

584


Is c++ vector dynamic?

574


What is data type in c++?

561


What is pair in c++?

630


What do you understand by zombie objects in c++?

620


A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, a saleperson who sells $5000 worth of merchandise in a week receives $200 plus 9 percent of $5000, or a total of $650. You have been supplied with a list of items sold by each salesperson. The values of these items are as follows: Item Value A 239.99 B 129.75 C 99.95 D 350.89 Write a program that inputs one salesperson's items sold in a week (how many of item A? of item B? etc.) and calculates and displays that salesperson's earnings for that week.

3415


What is operator overloading in c++ example?

655