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
  • 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...

  • #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...

  • 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...

  • Please write the complete code in C. Write a C function that prints the minimum spanning...

    Please write the complete code in C. Write a C function that prints the minimum spanning tree of a graph. At the end, print the weight of the spanning tree. A suggested report format is shown in the following example. Source Vertex To Vertex Weight A B 2 A C 4 B D 3 D E 1 Total weight of spanning tree: 10 Your main program will read a graph from DataIn file to an adjacency table before calling the...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

  • 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:...

  • Your task is to develop a large hexadecimal integer calculator that works with hexadecimal integers of...

    Your task is to develop a large hexadecimal integer calculator that works with hexadecimal integers of up to 100 digits (plus a sign). The calculator has a simple user interface, and 10 \variables" (n0, n1, ..., n9) into which hexadecimal integers can be stored. For example a session with your calculator might look like: mac: ./assmt1 > n0=0x2147483647 > n0+0x3 > n0? 0x214748364A > n1=0x1000000000000000000 > n1+n0 > n1? 0x100000000214748364A > n0? 0x214748364A > exit mac: Note: \mac: " is...

  • 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
ADVERTISEMENT