Jump to content
• Advertisement

Public Group

Explanation

This topic is 4960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Everyone Im still quite new at programming and was wondering if someone can explain why int X & Y are used when coding. I have read a few books on these but just cant get my head around it. Many Thanks

Share this post

Share on other sites
Advertisement
Do mean like in C/C++ where you can have
int X,Y;

People can choose whatever variable names they want.

Tell me if you are talking about something else.

Share this post

Share on other sites
Yes thats right, sorry for confusing you. I just need it eplained to me what that do exactly

Share this post

Share on other sites
Varibles do what you want them to do, simply put. You could declare your int variables RUTABEGGA and NANTUCKET for all it's worth to the program. I think introductory programming gets you used to them because a)they're short to type, b)they're easy to remember, and c)because that's what's been done for so many years.

I'm not sure why X and Y became such popular names for variables in mathematics, but since they are used so much, it's just natural for people to name simple programming variables X and Y as well.

In more complex, specific situations, X and Y are very often used to denote spatial co-ordinates. You can position something on a grid using X and Y as axes. This is a convention almost everybody uses when programming.

Hope you find this helpful
As ever,
**Cosmic**

Share this post

Share on other sites
An int (integer variable) is a location in system memory that you can use to store an integer value, i.e. any "whole" number. You can name a variable anything you want (except that there are limitations on the size of a name and there are certain characters that can not be included). You have to declare a variable so that the compiler knows what it is and what type it is. In C you most declare a variable at the beginning of the scope that it is used in. In C++ you can declare it anywere in the scope before it is used. THe code
 int X,Y;
declares two integer variables one named X and the other named Y.

Share this post

Share on other sites
Thanks for your time evryone this is much appreciated.
So X & Y are varibles am I right? what exactly do they represent or are they equavilent to something in the coding world.

Share this post

Share on other sites
They are variables yes. As Cosmic One said, X and Y are typically used to represent spatial co-ordinates. In geometry, 'x' is often used to represent the width or horizontal position of an entity, 'y' represents the height or vertical element of an entity and 'z' represents 'depth'.

So, in game programming we will often use x and y to represent the 2d position of an object in worldspace, where 'x' denotes how far 'across' the screen (or world) a point is and 'y' denotes how far 'up' it lies.

Note that this isn't always the case, but it is the common way of doing things. As Cosmic One said, you could choose to call these variables anything - but x,y and z are often used because their meaning is a globally understood.

Share this post

Share on other sites
Hi I have an example from a book that Im reading here is the problem Im not understanding how int x, int y work????

#include <iostream>

int Add (int x, int y)
{
std::cout << "In Add(), received "<< x << " and " << Y << "\n";
Return (x+y);

}

int main()
{
std::cout << "I'm in main()!\n";
std::cout << "\nCalling Add()!\n";
std::cout << "The value returned is: " << Add(3,4);
std::cout << "\nBack in main().\n";
std::cout << "\nExiting...\n\n";
return 0;
}

Share this post

Share on other sites
main is passing the parameter 3 and 4 to the function add, and is temporarily calling them x and y. It then adds them and prints out the result. X and Y aren't coordinates just variable names that could be anything.

****Im assuming the capital Y should be y****

Share this post

Share on other sites
think in this way.computer is a really stupid pile of shit.if you want it to remember to something,you will have to tell him every single detail. Type int x will be equvilent to say "I want you to remember a integer from now one called x." and type int x = 1 is same as "I want you to remember a integer called x which is equal to 1". similarly int y will be a integer called y, int y = 1 is a integer called y which is 1.

in case of your example program, that means you have a function which takes 2 integer nameingly x and y. and output the value of x+y.

hope this helps.

Share this post

Share on other sites

• Advertisement
• Advertisement

• Popular Contributors

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5
• Advertisement

• 14
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631434
• Total Posts
3000048
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!