473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

(int *) variable

Hello everybody.

What does an (int *) type of variable mean?

Thanks

Derek

Nov 14 '05 #1
2 1398
Bilbo wrote:
Hello everybody.

What does an (int *) type of variable mean?

Thanks

Derek


It is a pointer to an int i.e. the variable stores the memory location
of an int rather than the actual int itself.

You use (int *) like this:

int a;
int *p;

a = 42;
p = &a; /* p now contains the memory location of a */
*p = 21; /* a now contains the value 21 */

So you use & to get the address of a variable, and you use * in the
context *p to dereference the pointer i.e. to get at the value it is
pointing to.

Hope this helps,
Sam
Nov 14 '05 #2

"Sam Jervis" <sa*@heffalump.me.uk> wrote in message

You use (int *) like this:

int a;
int *p;

a = 42;
p = &a; /* p now contains the memory location of a */
*p = 21; /* a now contains the value 21 */

This is correct but maybe leaves the OP wondering "what is the point of
that?".

One answer is that a C function can return only one value. If we want a
function "getcursorpos" we need to return both x and y.

we do it like this.

/* globals maintained by the cursor handling routines */
int g_cursorxpos;
int g_cursorypos;

void getcursorpos(int *x, int *y)
{
*x = g_cursorxpos;
*y = g_cursorypos;
}

void callingfunction(void)
{
int cx;
int cy;

getcursorpos(&cx, &cy);
printf("The cursor is at position %d %d\n", cx, cy);
}
The most common use however is to pass an array of integers to another
function. For instance if we want to calculate the mean of a list of numbers
we would write

int mean(int *array, int N)

However the details of pointer and arrays are maybe best left until you've
got the idea of storing addresses in pointers.
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ben | last post by:
Hi all, I'm not yet good at thinking the right way in c++ so although I could solve this problem, I'm not sure if they way I'm thinking of is the best way to do it. I need a data type or class...
2
by: Lu | last post by:
Hello, I am wondering how to protect a global variable in a header file from external access. So I googled and found: "The keyword 'static' has two different uses, depending on whether it is...
8
by: shyju_kambi | last post by:
when a 'const int ' is declared, where is it been created(in RAM?) #include<stdio.h> int main() { const int i=10; const int *p; p=&i; *p=12; printf("\n %d %d",i,*p);
4
by: Bilgehan.Balban | last post by:
Hi, The following code: #include <stdio.h> // const int const_asize = 10; #define define_asize = 10; int array = {1,2,3,4,5,6,7,8,9,0};
16
by: Julia | last post by:
Hi, there, In C programming, for pointer, I saw two programming styles: one is connecting '*' with variable, like, 'int *i'; the other is connecting '*' with data type, like, 'int* i' I...
3
by: Michael | last post by:
Hi, I am a little confused about & and int &. Do they both mean reference? int a; int* b= & a ; (& here mean reference of a) int& b = a ; ( How to understand & precisely here?) Thanks...
29
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is:...
7
by: stefan.istrate | last post by:
I have a short int variable and I'm trying to read it with scanf("%d",&x); but I'm getting a warning message which sounds like this: warning: format '%d' expects type 'int*', but argument 2 has...
28
by: Tony Johansson | last post by:
Hello! If I write this statement int number = new int(); I don't get compiler error or run time error but how will the compiler read such a statement ? For example will number be a reference...
50
by: Mahendra | last post by:
I have following code snippet - int *createIncidenceMatrix(int numEdges, int numVertices) { int *p = (int *) calloc((numEdges*numVertices), sizeof(int)); if(p == NULL) { printf("Could not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.