473,503 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why this code has errors?

hello,
I am trying following code that help me to understand difference
between what happens when value is assigned to pointer or reference but
it has some errors how to remove that?
#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
4 1153
ra*******@gmail.com wrote:
void main()
According to the last ISO C standard, main() must have a int
return type. Thus, "int main()" is the correct definition for
main(), not "void main()".
int i;
int &k=i;


That's not C. You cannot write that in C.
You are using references, which are C++.
Nov 15 '05 #2
In article <11**********************@o13g2000cwo.googlegroups .com> ra*******@gmail.com writes:
....
int &k=i;


This is not C.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 15 '05 #3
ra*******@gmail.com wrote:
hello,
I am trying following code that help me to understand difference
between what happens when value is assigned to pointer or reference but
it has some errors how to remove that?
#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);
}


#include <stdio.h>
int /* mha: was 'void' */ main(void)
{
int i;
int *k /* mha: was '&k' */ = &i; /* mha: OP's initialization was
'=i', which both assigns an
int to a pointer and uses
the uninitialized value of i
*/
k++; /* mha: unchanged, since k is never
dereferenced (thank goodness) */
printf("val of i is %d\n", i);
k = (int *) 200; /* mha: cast introduced, but otherwise
unchanged, since k is never
dereferenced (thank goodness) */
printf("val of i is %d\n", i);
{
/* mha: block introduced because of what would be a C89 (C90)
error of a misplaced declaration. I could have moved the
declaration to the beginning of the enclosing block instead. */
int *p = &i;
p++; /* mha: unchanged, since p is never
dereferenced (thank goodness) */
printf("val of p is %p\n", (void *) p); /* mha: was
'printf("val of p is %d\n", p);' */
}
printf("val of i is %d\n", i);
return 0; /* mha: added */
}


Nov 15 '05 #4


ra*******@gmail.com wrote:
hello,
I am trying following code that help me to understand difference
between what happens when value is assigned to pointer or reference but
it has some errors how to remove that?

You're in the wrong newsgroup, what you have is C++. Try comp.lang.c++.


Brian

Nov 15 '05 #5

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

Similar topics

6
2387
by: amitavabardhan | last post by:
How can I return an error code from a sql server stored procedure and use it in my asp page to generate an alert indicating that some error has ocurred?
14
3403
by: root | last post by:
Hi group, Apologies in advance if this has been asked somewhere before, but I haven't managed to get anything from the Google archives - I've been getting introductory guides to C++ all day...
2
2576
by: Kavitha Rao | last post by:
Hi, I am getting the following errors while trying to run this snippet in Microsoft Visual C++.Can't seem to print the crc value stored. /* +++Date last modified: 05-Jul-1997 */ /* Crc - 32...
19
2236
by: Swaregirl | last post by:
Hello, I would like to build a website using ASP.NET. I would like website visitors to be able to download code that I would like to make available to them and that would be residing on my...
2
1107
by: Stephen Noronha | last post by:
Hi, I get an error "System.Data.SqlClient.SqlException", after my Stored Procedure runs and i saw an article for debugging through the Stored procedure using VS .Net....
41
1883
by: Jordan | last post by:
While writing some code, I realized I had never developed a consistent pattern for checking errors from a method. I have two styles I jump back and forth between, but I'm wondering which is...
10
2194
by: dbuchanan | last post by:
Hello, >From time to time my vb2005 form disappears and is replaced by the following errors. Rebuilding the application never helps. However the errors never affects the operation of my...
24
5263
by: pat | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo {
27
2687
by: David Golightly | last post by:
This is just a quick poll for all you web devs out there: What browsers do you test on/are concerned about compatibility with? Obviously, you're going to test on current-generation browsers such...
9
1683
by: Jens Jensen | last post by:
Hello all, I need some design advice for my web service. I' have written a web service that exposes a function that takes some parameters and return an xml.
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
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
7463
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
5581
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,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.