By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

another weird unexplained anomaly!

P: n/a


Fixed font - Proportional font
string initilization WHY?
All 2 messages in topic - view as tree
puzzlecracker Jan 29, 10:47 pm show options

Newsgroups: comp.lang.c
From: "puzzlecracker" <ironsel2...@gmail.com> - Find messages by this
author
Date: 29 Jan 2005 22:47:59 -0800
Local: Sat, Jan 29 2005 10:47 pm
Subject: string initilization WHY?
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse

Why would this work? - and it does! any thoughts?
#include<iostream>

using namespace std;
void init(char **str){ *str="Awesome"; }
main(){

char * str;

init(&str);
cout<<str<<endl;
}

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
puzzlecracker wrote:


Fixed font - Proportional font
string initilization WHY?
All 2 messages in topic - view as tree
puzzlecracker Jan 29, 10:47 pm show options

Newsgroups: comp.lang.c
From: "puzzlecracker" <ironsel2...@gmail.com> - Find messages by this
author
Date: 29 Jan 2005 22:47:59 -0800
Local: Sat, Jan 29 2005 10:47 pm
Subject: string initilization WHY?
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse

Why would this work? - and it does! any thoughts?
#include<iostream>

using namespace std;
void init(char **str){ *str="Awesome"; }
main(){

char * str;

init(&str);
cout<<str<<endl;
}


Well, technically it shouldn't work because main() is not a valid prototype
for main. It should be 'int main()'. But that is beside the point here.

Other than that, what is the problem? It is equivalent to

int main()
{
char* str;

str = "Awesome";
cout << str << endl;
}

Why wouldn't it work?

Ian

Jul 23 '05 #2

P: n/a
"puzzlecracker" <ir*********@gmail.com> writes:

Why would this work? - and it does! any thoughts?

I think it would help us reply constructively if you could explain what's so
weird, unexplained or anomalous about the pieces of code you're posting, so
that we could focus our comments accordingly. Is it the "main()" that you
find so weird? What sort of "thoughts" do you want?

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.