Pointers

Jun 28, 2012 at 1:54am
The instructions are :

.Write a c++ program that creates a decimal pointer, creates a variable set to a decimal value, then assigns the address of the variable to the pointer. User the pointer to print out the address and the value being pointed to by the pointer.

My code is :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

int main()
{
    int count = 5.1;
    int *pCount = &count;
    
    cout << "The Value of the count is " << count << endl;
    cout << "The address of count is " << &count << endl;
    cout << "The address of pCount is " << &pCount << endl;
    
    system("Pause");
    return 0;
}



How do i declare a decimal, i used int, but it prints out 5 instead of 5.1
Jun 28, 2012 at 2:19am
Use float or double to store decimal values. int is for integers only.
Jun 28, 2012 at 2:24am
yeah im dumb i used double instead and it works fine now, thanks anyways :)
Topic archived. No new replies allowed.