will this work?? | | |
hey
is anything wrong with this program???
int *array(int n){
return new int(n);
}
int main(){
int *p = array(10);
for( int i = 0; i < 10; i++ ) {
p[i] = 0;
}
printf( "%d\n", p[0] );
p = array(10);
printf( "%d\n", p[0] );
return 0;
} | | | | re: will this work??
hijkl wrote: Quote:
hey
is anything wrong with this program???
Yes. It's not C. Quote:
int *array(int n){
return new int(n);
And here's the non-C construct. Quote:
}
int main(){
int *p = array(10);
for( int i = 0; i < 10; i++ ) {
p[i] = 0;
}
printf( "%d\n", p[0] );
p = array(10);
printf( "%d\n", p[0] );
return 0;
}
| | | | re: will this work??
>is anything wrong with this program???
Yes. There is no 'new' in C. Quote:
int *array(int n){
> return new int(n);
}
int main(){
> int *p = array(10);
> for( int i = 0; i < 10; i++ ) {
> p[i] = 0;
> }
> printf( "%d\n", p[0] );
> p = array(10);
The above line causes a memory leak (except for the problem that it
shouldn't compile in the first place). You have allocated memory
and then throw away the last pointer to it. Quote:
> printf( "%d\n", p[0] );
> return 0;
}
| | | | re: will this work??
does it matters if its c or c++??
ok consider it as c++..:) | | | | re: will this work??
"hijkl" <s_mahida@yahoo.comwrites: Quote:
does it matters if its c or c++??
Does *what* matter?
You need to provide context when posting a followup. Don't assume
that your readers have seen the parent article. See
<http://cfaj.freeshell.org/google/>. (The Google bug originally
described on that page has been corrected. so there's no excuse.) Quote:
ok consider it as c++..:)
This is comp.lang.c; we don't discuss C++ here. Finding a newsgroup
where they do is left as an exercise.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister" | | | | re: will this work??
On 6 Mar 2007 21:38:52 -0800, "hijkl" <s_mahida@yahoo.comwrote: Quote:
>does it matters if its c or c++??
>ok consider it as c++..:)
If you want to discuss c++, go to a newgroup where it is topical.
Remove del for email | | | | re: will this work??
hijkl wrote: Quote:
hey
is anything wrong with this program???
Yes. Quote:
int *array(int n){
return new int(n);
^^^^^^^^^^^^^^^^^
Syntax error. No reason to go further (unless it's to comp.lang.c++
where they may like this C syntax error). Quote:
}
int main(){
int *p = array(10);
for( int i = 0; i < 10; i++ ) {
^^^^^^^^^
I hope your C compiler is one for C99, else this is a syntax error. Quote:
p[i] = 0;
}
printf( "%d\n", p[0] );
^^^^^^^^
Using a variadic function with no prototype in scope is a naughty thing
to do. Quote:
p = array(10);
printf( "%d\n", p[0] );
return 0;
}
>
| | | | re: will this work??
hijkl wrote: Quote:
does it matters if its c or c++??
ok consider it as c++..:)
Then it is off-topic in comp.lang.c. We don't answer questions about
how to program in Algol, Fortran, or Cobol either. | | | | re: will this work??
hijkl said: Quote:
hey
is anything wrong with this program???
Yes. It won't compile as C90, as C99, or even (off-topically) as C++.
My suggestions? (a) decide on a language, and then (b) learn it.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www. | | | | re: will this work??
hehe
u guys making issue :)
anyways i will post in c++ grp..
u guys better have invested time in solving problem :)
enjoyy | | | | re: will this work??
hijkl said: Quote:
hehe
u guys making issue :)
anyways i will post in c++ grp..
Good. Problem solved. Quote:
u guys better have invested time in solving problem :)
We already did.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www. | | | | re: will this work??
hijkl wrote: Quote:
hehe
u guys making issue :)
anyways i will post in c++ grp..
u guys better have invested time in solving problem :)
enjoyy
Please quote context and refrain from meaningless abbreviations like
'u', 'grp' etcetera. If not, you're unlikely to get helpful responses
in comp.lang.c++. | | | | re: will this work??
hijkl wrote: Quote:
>
hey
is anything wrong with this program???
>
int *array(int n){
return new int(n);
}
int main(){
int *p = array(10);
for( int i = 0; i < 10; i++ ) {
p[i] = 0;
}
printf( "%d\n", p[0] );
p = array(10);
printf( "%d\n", p[0] );
return 0;
}
Yes.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews | | | | re: will this work??
hijkl wrote: Quote:
>
does it matters if its c or c++??
Yes Quote:
ok consider it as c++..:)
No. c.l.c++ is ---thataway.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews | | | | re: will this work??
On 6 Mar 2007 23:35:17 -0800, "santosh" <santosh.k83@gmail.comwrote: Quote:
>hijkl wrote: Quote:
>hehe
>u guys making issue :)
>anyways i will post in c++ grp..
>u guys better have invested time in solving problem :)
>enjoyy
>
>Please quote context and refrain from meaningless abbreviations like
>'u', 'grp' etcetera. If not, you're unlikely to get helpful responses
>in comp.lang.c++.
Since we are discussing English, it is 'et cetera'. Two words. http://en.wikipedia.org/wiki/Et_cetera
OK, That is not an authoritative source. Finding the authoritative
source is left as an exercise to the other pedantic residents of clc.
Have a nice day,
Pradeep
--
All opinions are mine and do not represent the views or
policies of my employer.
R Pradeep Chandran rpc AT pobox DOT com | | | | re: will this work??
R Pradeep Chandran wrote: Quote:
On 6 Mar 2007 23:35:17 -0800, "santosh" <santosh.k83@gmail.comwrote: Quote:
hijkl wrote: Quote:
hehe
u guys making issue :)
anyways i will post in c++ grp..
u guys better have invested time in solving problem :)
enjoyy
Please quote context and refrain from meaningless abbreviations like
'u', 'grp' etcetera. If not, you're unlikely to get helpful responses
in comp.lang.c++.
>
Since we are discussing English, it is 'et cetera'. Two words.
You got me there! Thanks.
[ ... ] Quote:
OK, That is not an authoritative source. Finding the authoritative
source is left as an exercise to the other pedantic residents of clc.
The intention in warning the poster was a genuine interest in help him
reach the maximum possible audience for his posts, since many
otherwise potentially helpful posters ignore, or post unhelpful
replies, to posts containing such "abbreviations." I any case it
wasn't meant as an attempt at demonstrating pedanticism. | | | | re: will this work??
santosh said: Quote:
>
R Pradeep Chandran wrote: Quote:
>On 6 Mar 2007 23:35:17 -0800, "santosh" <santosh.k83@gmail.com>
<snip> Quote: Quote: Quote:
>
>Please quote context and refrain from meaningless abbreviations like
>'u', 'grp' etcetera. If not, you're unlikely to get helpful
>responses in comp.lang.c++.
>>
>Since we are discussing English, it is 'et cetera'. Two words.
>
You got me there! Thanks.
No, he didn't. We were discussing English, not Latin. (He is, however,
correct that 'et cetera' comprises two words rather than one.) Quote:
>
[ ... ] Quote:
>OK, That is not an authoritative source. Finding the authoritative
>source is left as an exercise to the other pedantic residents of clc.
>
The intention in warning the poster was a genuine interest in help him
reach the maximum possible audience for his posts, since many
otherwise potentially helpful posters ignore, or post unhelpful
replies, to posts containing such "abbreviations." I any case it
wasn't meant as an attempt at demonstrating pedanticism.
It's 'pedantry', not 'pedanticism'. :-)
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www. | | | | re: will this work??
On 7 Mar 2007 11:44:53 -0800, "santosh" <santosh.k83@gmail.comwrote: Quote:
>R Pradeep Chandran wrote: Quote:
>OK, That is not an authoritative source. Finding the authoritative
>source is left as an exercise to the other pedantic residents of clc.
>
>The intention in warning the poster was a genuine interest in help him
>reach the maximum possible audience for his posts, since many
>otherwise potentially helpful posters ignore, or post unhelpful
>replies, to posts containing such "abbreviations." I any case it
>wasn't meant as an attempt at demonstrating pedanticism.
I realized that. I consider being pedantic a good quality in a place
like this. It is one of the reasons why I lurk here. That and the
occasional dry humor. I guess I should've added a smiley to my post.
:-)
<OT about humor>
There is a regular poster who advised a certain researcher at Bell
labs about what is topical in clc. There were a lot of people who were
humor impaired and the resulting flames were very colorful.
</OT>
Have a nice day,
Pradeep
--
All opinions are mine and do not represent the views or
policies of my employer.
R Pradeep Chandran rpc AT pobox DOT com | | | | re: will this work??
"Richard Heathfield" <rjh@see.sig.invalidwrote in message
news:obadncXy8pJFvXLYRVnyvAA@bt.com... Quote:
>
It's 'pedantry', not 'pedanticism'. :-)
.... said the pedant. :-)
-Mike | | | | re: will this work??
CBFalconer <cbfalconer@yahoo.comwrites: Quote:
hijkl wrote: Quote:
>>
>hey
>is anything wrong with this program???
>>
> int *array(int n){
> return new int(n);
> }
> int main(){
> int *p = array(10);
> for( int i = 0; i < 10; i++ ) {
> p[i] = 0;
> }
> printf( "%d\n", p[0] );
> p = array(10);
> printf( "%d\n", p[0] );
> return 0;
> }
>
Yes.
Do you never tire of being such a pedantic, picky, arrogant arse? | | | | re: will this work??
Richard wrote: Quote:
CBFalconer <cbfalconer@yahoo.comwrites: Quote:
>hijkl wrote: Quote:
>>>
>>is anything wrong with this program???
>>>
>> int *array(int n){
>> return new int(n);
>> }
>> int main(){
>> int *p = array(10);
>> for( int i = 0; i < 10; i++ ) {
>> p[i] = 0;
>> }
>> printf( "%d\n", p[0] );
>> p = array(10);
>> printf( "%d\n", p[0] );
>> return 0;
>> }
>>
>Yes.
>
Do you never tire of being such a pedantic, picky, arrogant arse?
No. Both answers are accurate and responsive.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,366 network members.
|