473,320 Members | 2,027 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,320 software developers and data experts.

help to run this code...

hello,
I am trying following code but it has errors how to solve that
and please help to know difference between value assigned to
pointer/reference?
#include <stdio.h>
void main()
{
int i;
int &k=i;
k++;
printf("val of i is %d\n",i);
k=200;
printf("val of i is %d\n",i);
int *p=&i;
p++;
printf("val of p is %d\n",p);
printf("val of i is %d\n",i);
}

Nov 15 '05 #1
3 1299
ra*******@gmail.com wrote:
hello,
I am trying following code but it has errors how to solve that
and please help to know difference between value assigned to
pointer/reference?
#include <stdio.h>
void main() int main(void) /* main() returns *int* */ {
int i;
int &k=i;
As you've already been told, references are not part of C.
news:comp.lang.c++ is down the hall. k++;
printf("val of i is %d\n",i);
k=200;
printf("val of i is %d\n",i);
int *p=&i;
p++;
printf("val of p is %d\n",p);
printf("val of i is %d\n",i);
}


HTH,
--ag
--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Nov 15 '05 #2
what you trying to do has some C++ feature (references)

int &k = i;

is not valid C but it is a valid C++ construct (k will become an alias
to i)
so k = 1; or i = 1; is the same;

int *p = &i;

makes p point to i (hold the address of i)

p++;
increment the address p is pointing too and does not have any affect on
i itself.

Nov 15 '05 #3
On Wed, 13 Jul 2005 19:53:38 +0200, <ra*******@gmail.com> wrote:
hello,
I am trying following code but it has errors how to solve that
and please help to know difference between value assigned to
pointer/reference? #include <stdio.h>
void main() that should be int main(), not everyone is using Visual C++ ... {
int i; if you want to return a value, you should assing one
int i = 23; int &k=i; int *k=&i;
I think you mean that k++; (*(k))++;
to increase the value on which the pointer is pointing printf("val of i is %d\n",i);
k=200; *k=200;
change the value and not the pointer printf("val of i is %d\n",i);
int *p=&i; that is better than the one above p++; (*(p))++;
same thing printf("val of p is %d\n",p); printf("val of p is %d\n",*p);
you want to printf the value and not the address printf("val of i is %d\n",i);
}


the whole code:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i = 23;
int *k=&i;
(*(k))++;
printf("val of i is %d\n",i);
*k=200;
printf("val of i is %d\n",i);
int *p=&i;
(*(p))++;
printf("val of p is %d\n",*p);
printf("val of i is %d\n",i);
system("PAUSE");
}

regards
Nov 15 '05 #4

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

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
6
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and...
4
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
1
by: glenn123 | last post by:
Hi, i am just about out of time to produce a working jukebox which has to perform these functions: to play music files when a track is chosen from a list which when the user presses the change genre...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.