Advertisement
Guest User

HW1

a guest
Feb 10th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4.  
  5. int *intPointer;
  6. int main()
  7. {
  8.     char nameVar[30];
  9.     short exampleVar;
  10.     short shortVar1;
  11.     short shortVar2;
  12.     int intVar1;
  13.     int intVar2;
  14.     int intVar3;
  15.     char *charPointer;
  16.     float floatVar1;
  17.     float floatVar2;
  18.     exampleVar = 99;
  19.     shortVar1 = 12;
  20.     shortVar2 = 24;
  21.     intVar1 = 16;
  22.     intVar2 = 78;
  23.     intVar3 = 10;
  24.     floatVar1 = 6;
  25.     floatVar2 = 3;
  26.     charPointer = (char *)malloc(2000);
  27.     intPointer = (int *)malloc(1000);
  28.     strcpy(charPointer, "David Barnes");
  29.     // Example: Below statement illustrates how to display address of the variable exampleVar
  30.     printf("\n The address of variable exampleVar is : %p", &exampleVar);
  31.     // DONE – Please uncomment and complete each statement below to print the
  32.     // DONE memory location allocated to the respective variable
  33.     printf("\n The address of variable shortVar1 is : %p", &shortVar1);
  34.     printf("\n The address of variable shortVar2 is : %p", &shortVar2);
  35.     printf("\n The address of variable charPointer is : %p", &charPointer);
  36.     printf("\n The memory allocated for charPointer is : %d bytes.", _msize(charPointer));
  37.     printf("\n The address of variable nameVar is : %p", (void *)&nameVar);
  38.     printf("\n The address of variable intVar1 is : %p", &intVar1);
  39.     printf("\n The address of variable intVar2 is : %p", &intVar2);
  40.     printf("\n The address of variable intVar3 is : %p", &intVar3);
  41.     printf("\n The address of variable intPointer is : %p", &intPointer);
  42.     printf("\n The memory allocated for intPointer is : %d bytes.", _msize(intPointer));
  43.     printf("\n The address of variable floatVar1 is : %p", &floatVar1);
  44.     printf("\n The address of variable floatVar2 is : %p", &floatVar2);
  45.     //DONE - Add proper lines of code to print the location and the amount of memory
  46.     //allocated to dynamic variables (pointers)
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement