Write a C program in which you will:
1. Prompt user to enter values the following variables: an integer, a double, and a character.
2. Create a pointer for each of the variable.
3. Using only the pointers, increase the variables by 1.
4. Print out the value and the address of each variable.
Name your program task1.c
Output of your program should look like this:
hb117@uxb4:~$ gcc -Wall task1.c -o task1
hb117@uxb4:~$ ./task1
Please enter an integer, a double and a character:
99 1.3 a
100 0x7ffcc9aeaadc
2.300000 0x7ffcc9aeaae0
b 0x7ffcc9aeaadb
hb117@uxb4:~$
1
Expert's answer
2016-11-01T16:06:10-0400
#include <stdio.h>
int main(int argc, char *argv[]) { int a; char c; double d; int* p_a = &a; char* p_c = &c; double* p_d = &d; printf("Please enter an integer, a double and a character:"); scanf("%d %lf %c", &a, &d, &c); *p_a += 1; *p_c += 1; *p_d += 1; printf("%d %p\n", *p_a, p_a); printf("%lf %p\n", d, p_d); printf("%c %p\n", c, p_c); return 0; }
Comments
Leave a comment