____________C PROGRAMMING________________ 1. Write a program that declares and i
ID: 3759590 • Letter: #
Question
____________C PROGRAMMING________________
1. Write a program that declares and initializes three standard variables: a double, an int, and a string (character array). You can set the variables to any value you like. Size the string to hold 5 bytes including the terminating null character. (Your string will be 4 characters.)
Print to the screen the address, size of, and value of each variable. You can use the printf() format specifier "0x%x" to view the addresses in hexadecimal. (The initial "0x" before the hex digits is optional and helps indicate to the viewer this is a hexadecimal number.) Use the sizeof() operator to determine the memory size allocated for each vairable.
2. Add three pointer variable declarations to the above code: a pointer to double, a pointer to int, and a pointer to char. Initialize each pointer to the address of the associated variable you declared above.
EXAMPLE) int *pI; // pI is a pointer to int
Print to the screen the address, size of, and value stored in each pointer variable. Do not de-reference the pointers.
Next, USING ONLY THE POINTERS, print the value stored in each data variable you created in step 1. Here, you will need to de-reference the pointers. Now you are looking for information about what the pointers are pointing to.
Explanation / Answer
Solution for above two programs is below. It contains the both Normal Variable and Pointer Variable Size, Addredd and Value stored in Interger, Double and Char Array corresponding Declaration, Intilization and printing ..
#include<stdio.h>
int main()
{
int number = 5, *pI;
pI = & number; // Assigning Interger variable to interger pointer
double number2 = 10.5, *pD;
pD = &number2; // Assigning Double variable to Double pointer
char arry[] = "hell", *pc;
pc = &arry; // Assigning Char Array variable to Char Array Pointer
// Size, Address and Value stored in each Interger Variable, Double Variable and Charecter Variable
printf("Interger Size is = %d , Address is = 0x%x and Value is = %d: ",sizeof(number), &number, number);
printf("Double Size is = %d, Address is = 0x%x and Value is = %lf: ",sizeof(number2), &number2, number2);
printf("Charecter Array Size is = %d, Address is = 0x%x and Value is = %s: ",sizeof(arry), &arry, arry);
// Pointers Size, Address and Value stored in each Interger Pointer, Double Pointer and Charecter pointer
printf("Pointer Interger Size is = %d , Address is = 0x%x and Value is = %d: ",sizeof(pI), &pI, *pI);
printf("Pointer Double Size is = %d, Address is = 0x%x and Value is = %lf: ",sizeof(pD), &pD, *pD);
printf("Pointer Charecter Array Size is = %d, Address is = 0x%x and Value is = %s: ",sizeof(pc), &pc, pc);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.