LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-28-2004, 09:01 AM   #1
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Rep: Reputation: 18
Fundamental Question in C and C++


Hi
my friend was asked this question in an interview ... any answers ??

GIve a valid C assignment statement that compiles correctly both on a C and C++ compiler, but works differently in C and C++.

thanks
 
Old 07-28-2004, 09:54 AM   #2
R00ts
Member
 
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 545

Rep: Reputation: 30
Hmm that's a good one. I can't think of anything off the top of my head. I'm interested in what a valid answer would be.
 
Old 07-28-2004, 10:15 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
I suggest this code as C does implicitly conversion from char 'a' to int but C++ no.
Code:
#include <stdio.h>

int main(void)
{
    printf("%i\n", sizeof('a'));
    return 0;
}
 
Old 07-28-2004, 10:32 AM   #4
linux_ub
Member
 
Registered: May 2004
Location: NY
Distribution: fedora core 1
Posts: 65

Original Poster
Rep: Reputation: 18
when my friend asked me this question my first instinct was

int i = 5;

i donno if i am correct or no ... but i feel the above C statement is equivalent to the
int i = new int(5) in C++

comments awaited

thanks
 
Old 07-28-2004, 11:13 AM   #5
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
Why didn't the interviewer just ask your friend if he had read and memorised page 816, section 2.1 of Appendix B in Stroustup's 'The C++ Programming Language, Special Edition' ?

Would have been more to the point.

Maybe they could have asked him for the ISBN number too

Oh, if you want to look them up, the appendix is on this page: http://www.research.att.com/~bs/3rd.html as a pdf


Last edited by dakensta; 07-28-2004 at 11:27 AM.
 
Old 07-28-2004, 11:26 AM   #6
lone_nut
Member
 
Registered: Dec 2003
Location: Denmark
Distribution: Mandrake
Posts: 179

Rep: Reputation: 30
Quote:
Originally posted by Cedrik
I suggest this code as C does implicitly conversion from char 'a' to int but C++ no.
Code:
#include <stdio.h>

int main(void)
{
    printf("%i\n", sizeof('a'));
    return 0;
}
I compilled it and he is right.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Arch has fundamental personality issues otchie1 Arch 13 11-23-2005 08:16 PM
The Fundamental Differences Between Linux and Windows Charred Linux - News 23 10-30-2005 01:50 AM
Partition fundamental questions jfchui Linux - Newbie 7 04-23-2004 06:47 AM
Fundamental automated tasks dominant Linux - Newbie 6 02-20-2004 11:59 AM
Fundamental ipchains concept questionn... WeNdeL Linux - Security 2 12-19-2002 11:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration