Please fill in the blanks for C /* This task will do some basic programming using pointers. All will be written in main. Declare 2 integers and 2 floats and initialize them (no need for user inputs): i1,i2,f1,f2 Print all 4 variables’ */ /*Pointers Basic*/ #include int main() { printf("------------------------------------------------------------------------------------------------------------\n"); printf("Note: Pointers' values should be the same as the address of the variable it points to.\n"); printf("\tThe de-reference values of the pointers should be the same as the value of the variable it points to.\n"); printf("\tPointer pi1 points to i1. Pointer pi2 points to i2. Pointer pf1 points to f1. Pointer pf2 points to f2.\n"); printf("\tWhen printing values for the floats using the variables themselves or through de-referencing pointers, \ remember to round them to 3 decimal places.\n"); printf(" ------------------------------------------------------------------------------------------------------------\n\n"); // Declare 2 ints and 2 floats __1__ i1, i2; //the integers __2__ f1, f2; // the floats // Initialize all 4 variables __3__ = 3, i2 = -100; __4__ = 2.4564; f2 = -34.21234; //Print all four variables' values //Round the float to 3 decimal places printf("\nPrinting values:\n"); printf("i1 = __5__, i2 = __6__, f1 = __7__, f2 = __8__.\n", __9__, __10__, __11__, __12__); //Print all four variables' addresses printf("\nPrinting addresses:\n"); printf("i1's = __13__, i2's = __14__, f1's = __15__, f2's = __16__.\n", __17__, __18__, __19__, __20__); //Declare 2 pointer-to-int and 2 pointer-to-float // name 2 pointer-to-int pi1 and pi2 // name 2 pointer-to-float pf1 and pf2 __21__ __22__, __23__; //pointer-to-int pi1, pi2 __24__ __25__, __26__; //pointer-to-float pf1, pf2 //Initialize pointer-to-int pointers __27__ = __28__; //first pointer-to-int points to i1 __29__ = __30__; //second int pointer points to i2 //Initialize pointer-to-float __31__ = __32__; //first pointer-to-float points to f1 __33__ = __34__;//second float pointer points to f2 printf("\nPrinting pointers' addresses:\n"); printf("pi1's = __35__, pi2's = __36__, pf1's = __37__, pf2's = __38__.\n", __39__, __40__, __41__, __42__); printf("\nPrinting pointers' values:\n"); printf("pi1's = __43__, pi2's = __44__, pf1's = __45__, pf2's = __46__.\n", __47__, __48__, __49__, __50__); printf("\nPrinting pointers' de-reference values:\n"); printf("de-ref pi1 = __51__, de-ref pi2 = __52__, de-ref pf1 = __53__, de-ref pf2 = __54__.\n",__55__, __56__, __57__, __58__); return 0; }
Please fill in the blanks for C
/* This task will do some basic programming using pointers. All will be written in main.
Declare 2 integers and 2 floats and initialize them (no need for user inputs): i1,i2,f1,f2
Print all 4 variables’ */
/*Pointers Basic*/
#include<stdio.h>
int main()
{
printf("------------------------------------------------------------------------------------------------------------\n");
printf("Note: Pointers' values should be the same as the address of the variable it points to.\n");
printf("\tThe de-reference values of the pointers should be the same as the value of the variable it points to.\n");
printf("\tPointer pi1 points to i1. Pointer pi2 points to i2. Pointer pf1 points to f1. Pointer pf2 points to f2.\n");
printf("\tWhen printing values for the floats using the variables themselves or through de-referencing pointers, \
remember to round them to 3 decimal places.\n");
printf(" ------------------------------------------------------------------------------------------------------------\n\n");
// Declare 2 ints and 2 floats
__1__ i1, i2; //the integers
__2__ f1, f2; // the floats
// Initialize all 4 variables
__3__ = 3, i2 = -100;
__4__ = 2.4564; f2 = -34.21234;
//Print all four variables' values
//Round the float to 3 decimal places
printf("\nPrinting values:\n");
printf("i1 = __5__, i2 = __6__, f1 = __7__, f2 = __8__.\n", __9__, __10__, __11__, __12__);
//Print all four variables' addresses
printf("\nPrinting addresses:\n");
printf("i1's = __13__, i2's = __14__, f1's = __15__, f2's = __16__.\n", __17__, __18__, __19__, __20__);
//Declare 2 pointer-to-int and 2 pointer-to-float
// name 2 pointer-to-int pi1 and pi2
// name 2 pointer-to-float pf1 and pf2
__21__ __22__, __23__; //pointer-to-int pi1, pi2
__24__ __25__, __26__; //pointer-to-float pf1, pf2
//Initialize pointer-to-int pointers
__27__ = __28__; //first pointer-to-int points to i1
__29__ = __30__; //second int pointer points to i2
//Initialize pointer-to-float
__31__ = __32__; //first pointer-to-float points to f1
__33__ = __34__;//second float pointer points to f2
printf("\nPrinting pointers' addresses:\n");
printf("pi1's = __35__, pi2's = __36__, pf1's = __37__, pf2's = __38__.\n", __39__, __40__, __41__, __42__);
printf("\nPrinting pointers' values:\n");
printf("pi1's = __43__, pi2's = __44__, pf1's = __45__, pf2's = __46__.\n", __47__, __48__, __49__, __50__);
printf("\nPrinting pointers' de-reference values:\n");
printf("de-ref pi1 = __51__, de-ref pi2 = __52__, de-ref pf1 = __53__, de-ref pf2 = __54__.\n",__55__, __56__, __57__, __58__);
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images