Question

Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You can initialize the variable

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part 1

######

#include<stdio.h>

int main(){
   //variable declaration
   double a=10.2;
   int b=2;
   char c='a';
  
   //pointers
   double *p1=&a;
   int *p2=&b;
   char *p3=&c;
  
   //printing the address of variables in hex
   printf("Address of a=0x%x\n",&a);
   printf("Address of b=0x%x\n",&b);
   printf("Address of c=0x%x\n",&c);
  
   //printing the value of variables
   printf("Value of a=%f\n",a);
   printf("Value of b=%d\n",b);
   printf("Value of c=%c\n",c);
  
   //printing the value of pointers which is the address of variables it points
   printf("Value of pointer p1=%d\n",p1);
   printf("Value of pointer p2=%d\n",p2);
   printf("Value of pointer p3=%d\n",p3);
  
  
   //printing the size of variables
   printf("Size of a=%d\n",sizeof(a));
   printf("Size of b=%d\n",sizeof(b));
   printf("Size of c=%d\n",sizeof(c));
  
   //printing the size of pointers
   printf("Size of pointer p1=%d\n",sizeof(p1));
   printf("Size of pointer p2=%d\n",sizeof(p2));
   printf("Size of pointer p3=%d\n",sizeof(p3));
   return 0;
}

//##################### PGM END ##################################

OUTPUT
#######

C:\UsersJijinAVADocuments\DevC++_Workspace\Program1.exe Address of a-ΘΧ62feθθ Address of b-0x62fdfo Address of c-ax62fdfb Val

----------------------------------------------------------------------------------------------------------------------

Part II

##########

#include<stdio.h>
void ptrLab1(int xval){
   int x;
   x=xval;
   printf("Value of x=%d and Address of x=%p\n",x, (void*)&x);
}
void ptrLab2(int dummy){
   int y;
   printf("Value of y=%d and Address of y = %p\n",y, (void*)&y);
}
int main(){
   ptrLab1(7);
   ptrLab2(11);
   return 0;
}

//################## PGM END ################################

OUTPUT
########
C:UsersJijinA Documents\DevC++_Workspace\Program2.exe Value of x-7 and Address of x-00e00000062FDEC Value of y 7 and Address

Add a comment
Know the answer?
Add Answer to:
Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1) Write a program that: program starts; declares and initializes to zero an integer variable score;...

    1) Write a program that: program starts; declares and initializes to zero an integer variable score; declares and initializes to zero a float variable total; uses a for loop statement with integer x initialized to 1 going 5 iterations hence x<5 incremented by 0; input from keyboard integer score in range of 0 to 99; print on new line input value; adds score to total; switch x equals 3 break default x++; after exiting the loop calculate the average score;...

  • #include <stdio.h> int main(int argc, char *argv[]) {      char a, *pc, c[9];      int i, *pk, k[9];      a='...

    #include <stdio.h> int main(int argc, char *argv[]) {      char a, *pc, c[9];      int i, *pk, k[9];      a='z';      pc=&(c[8]);      pk=&(k[0]);      for (i=0; i<9; i++)     {           *pc=a-(char)i;           pc--;           *pk=(int)a-i;           pk++;           }                     return 0; }//end of main Answer the below questions with the above code Write out the memory map for the above C code in the following table. For array variables, list the address range for the entire array. Assume the memory address starts from 100, that is, the address for a...

  • You are given an integer array in the console program which declares and initializes it as...

    You are given an integer array in the console program which declares and initializes it as follows, for example: int int_array[] = {1, -3, 23, 4, 9, 2, 29, -3, 0, 2, 48, 7, 6, -1}; In that array there are n elements, where 0 < n < INT_MAX. Your program is to find the largest sum of any consecutive elements in that array. In the above example, the largest sum is obtained by adding 23, 4, 9, 2, 29,...

  • Run the C program below and complete the table showing all the variables. Add printf function...

    Run the C program below and complete the table showing all the variables. Add printf function calls to obtain the addresses and values of all 13 variables. (Count the array (ca) as 3 variable/values and also include argc and argv in the table). The table must show the Address, Name, Datatype, Scope, and Value of each variable on the stack. (Hint: use the sizeof function to double check your addresses.) Explain how different the actual memory allocations are from what...

  • Write a complete C program that does the following: . o Declare a and b as...

    Write a complete C program that does the following: . o Declare a and b as character variables. Initialize a to this value: 127 o Declare c as an unsigned character variable o Multiply a by 2 and store the result in variable b. o Multiple a by 2 and store the result in variable c. Print the values of a, b, and c. Use the %d specifier in each case. Declare d as an integer variable. Initialize d to...

  • Part 2) write a C++ program that declares a 2 dimensional array: int CSIIAssign3 [10][12]; Initialize...

    Part 2) write a C++ program that declares a 2 dimensional array: int CSIIAssign3 [10][12]; Initialize your array using a text file, user input or assign value while declaring the array, you can choose the method. Then, a. Write a loop to print first row of the array on one line, using cout. b. Write a loop to print first column of the array on one line, using cout. c. Write a loop to print first five rows of the...

  • int c = 75; int d = 100; int& r1 = c; int& r2 = d;...

    int c = 75; int d = 100; int& r1 = c; int& r2 = d; c++; r2++; Use the code above. Suppose the variable c lives at memory address 512, and d lives at the memory address 1024. The size of an integer is 4 bytes. After execution of the above code, draw labelled boxes for each of the 4 variables c, d, r1 and r2, and show their integer values. For r1 and r2, draw an additional arrow...

  • Problems: 1. Write a program to define the following variables, assign them values, and print their...

    Problems: 1. Write a program to define the following variables, assign them values, and print their values on screen: Integer x = 20, Float y = 40.45 Double z = 91.51e+5 Char w = A • • For the integer variable x, you need to print it in decimal notations, octal notations and hexadecimal notation. For the double variable y, you need to print it in double notations and scientific notation. 2. Write a program with the following three parts:...

  • Please Answer with C code. Will rate! Thanks 1) Write a program in C to demonstrate...

    Please Answer with C code. Will rate! Thanks 1) Write a program in C to demonstrate the use of &(address of) and *(value at address) operator. #include <stdio.h> void main() { int m=300; float fx = 300.60; char cht = 'z'; int *pt1; float *pt2; char *pt3; pt1= &m; pt2=&fx; pt3=&cht; a) print the address of variables (m, fx, cht) use & operation b) print the value at address of variables (m, Fx, cht) use & and * c) print...

  • Write a program that allows the user to enter an unsigned integer (the maximum value of...

    Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT