Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

Pointer Practice

Got an idea for a practice project / debug snippet / short-code contest / etc? Tell us about it here!

Pointer Practice

Postby Spyder638 on Sun Jul 12, 2009 1:18 pm

Code: Select all
#include "stdafx.h"
#include <iostream>
using namespace std;

void divide2(int * ptr);

int main()
{
   int x = 10;
   int y = 20;
   int * pointer = &x;
   cout << "x = " << x << " and it's address is " << pointer << endl;
   divide2(pointer);
   divide2( & y );
   cout << "x is now = " << x << " and y is now " << y << endl;
   system("pause");
}


void divide2(int * ptr)
{
   (*ptr) = (*ptr)/2;
}


Basically this was a practice for transferring varibles in between functions as well as pointers, what it does is divide by 2. :O
Spyder638
 
Posts: 1
Joined: Sun Jul 12, 2009 1:13 pm

Return to -- Code Practice Submissions --

Who is online

Users browsing this forum: No registered users and 0 guests