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

implicit typecast

Hello,

I have to write an exam and I am not sure about implicit typecasting. Can
somebody please tell me of what type the following c-statements are? And why
they are of this type? It is also possible that the statements are wrong.

first exercise:

int x;
unsigned int ux;
float f;
char *p1;
void *p3;
int (*pf)(void);
void (*pf2)(double);
int f1(void);
void f3(double x2);
p1 = p3;
x += f;
p3 + ux;
pf = f1();
pf2 == f3;
pf2 = f3;
pf = f1;
p3 ? x : f;
*p3;
second exercise:

int x;
float f;
char *p1;
int f1(int x1);
int f2(int x1, int x2);
int f3(double x1);
int (*pf)(int);
int (*pf2)(double);
p1 ? f1 : pf;
pf = f1;
pf = f1(x);
pf2 = pf;
pf == f1;
pf == pf2;
f = f3(f);
f1 == f2;
++f;
p1 ? i : f;

Thanks in advance!

Greets Pete
Nov 14 '05 #1
10 4577
Peter Drese <pd****@yahoo.de> scribbled the following:
Hello, I have to write an exam and I am not sure about implicit typecasting. Can
somebody please tell me of what type the following c-statements are? And why
they are of this type? It is also possible that the statements are wrong.


You wouldn't want us to do your homework for you, would you? This smells
suspiciously like it.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Outside of a dog, a book is a man's best friend. Inside a dog, it's too dark
to read anyway."
- Groucho Marx
Nov 14 '05 #2
> You wouldn't want us to do your homework for you, would you? This smells
suspiciously like it.


I'm sorry if you think so. Unfortunatly it is not my homework. In about
three weeks I have to write an exam at university about this stuff. I tried
to solve the exercise a couple of times but I'm not sure about my solutions.
If you want, I can post them but I don't want to influence anybody!

Greets Pete

Nov 14 '05 #3
In article <bt**********@online.de>, "Peter Drese" <pd****@yahoo.de>
wrote:
Hello,

I have to write an exam and I am not sure about implicit typecasting. Can
somebody please tell me of what type the following c-statements are? And why
they are of this type? It is also possible that the statements are wrong.


This smells like homework. Anyone who would be in a position teaching
C, and writing exams on the subject should know the answers to all of
these.

Nov 14 '05 #4
Clark Cox <cl*******@mac.com> writes:
In article <bt**********@online.de>, "Peter Drese" <pd****@yahoo.de>
wrote:
I have to write an exam and I am not sure about implicit typecasting. Can
somebody please tell me of what type the following c-statements are? And why
they are of this type? It is also possible that the statements are wrong.


This smells like homework. Anyone who would be in a position teaching
C, and writing exams on the subject should know the answers to all of
these.


Sometimes "write an exam" means "take an exam". I suspect that's
what Peter means.
--
"The expression isn't unclear *at all* and only an expert could actually
have doubts about it"
--Dan Pop
Nov 14 '05 #5
Peter Drese wrote:
I have to write an exam and I am not sure about implicit typecasting.
Can somebody please tell me
of what type the following c-statements are?
And why they are of this type?
It is also possible that the statements are wrong.

first exercise:


[snip]

The rule is:

Attempt to answer these homework questions yourself!
Then submit the questions along with your answers
and subscribers to comp.lang.c will be happy to help you.

Nov 14 '05 #6
Peter Drese wrote:
Hello,

I have to write an exam and I am not sure about implicit typecasting.
There is no such thing. A "cast" or "type cast" is defined as an
explicit type conversion. In C, this is accomplished via the cast
operator (which looks like the name of a type inside parentheses).
"Implicit type cast" is an oxymoron, since a cast can never be implicit.
Can
somebody please tell me of what type the following c-statements are?
Statements do not have types. A statement is sort of a syntactic unit
that "stands alone", so to speak. Statements are evaluated for
side-effects, and don't "return" a result. Expressions, on the other
hand, have a resulting value (unless the type is 'void') of a particular
type, and may be evaluated both for side-effects and for this result.
And why
they are of this type? It is also possible that the statements are wrong.


C's type rules can be somewhat complex. You'd do better to ask specific
questions.

<Remainder snipped>

Regardless of whether this is homework or not, the fact that it seems
very much like homework is enough for most of us to avoid simply
supplying the answers, particularly because you gave no indication of
any attempt to determine those answers yourself. If we see some effort
on your part to solve the problem, we can tell you whether you are right
or not, gauge your level of knowledge about the subject, and see where
you might have misconceptions. All this helps us to help you, and shows
that you are interested in learning, not just in receiving answers. Most
of us consider helping people learn to be a good use of our time, but
don't consider supplying free answers to be.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #7
"Peter Drese" <pd****@yahoo.de> writes:
I have to write an exam and I am not sure about implicit typecasting.


I think the phrase "write an exam" is ambiguous. Are you an
instructor creating a test for your students, or a student trying to
write answers for a test given to you by an instructor?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #8
On Mon, 5 Jan 2004, Peter Drese wrote:
Hello,

I have to write an exam and I am not sure about implicit typecasting. Can
somebody please tell me of what type the following c-statements are? And why
they are of this type? It is also possible that the statements are wrong.

first exercise:

int x;
unsigned int ux;
float f;
char *p1;
void *p3;
int (*pf)(void);
void (*pf2)(double);
int f1(void);
void f3(double x2);
p1 = p3;
x += f;
p3 + ux;
pf = f1();
pf2 == f3;
pf2 = f3;
pf = f1;
p3 ? x : f;
*p3;
I would recommend using www.google.ca to search for "n869". You will find
a copy of the draft of the ANSI C standard. Section 6.3 covers
"Conversions". If you can figure out what type the variable are then you
can figure out the result. For example, what is p3 and ux? I see that p3
is a pointer amd ux is an integer. Does ux get converted to a pointer? Or
does p3 get converted to an integer? If ux gets converted to a pointer
then maybe look in 6.3.2.3 Pointer of the standard.

I'm not going to give you the answer. If you don't do the work yourself
you will never remember but hopefully a good text book or the n869 file
will help you figure things out.
second exercise:

int x;
float f;
char *p1;
int f1(int x1);
int f2(int x1, int x2);
int f3(double x1);
int (*pf)(int);
int (*pf2)(double);
p1 ? f1 : pf;
pf = f1;
pf = f1(x);
pf2 = pf;
pf == f1;
pf == pf2;
f = f3(f);
f1 == f2;
++f;
p1 ? i : f;

Thanks in advance!

Greets Pete


--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
Nov 14 '05 #9
Kevin Goodsell <us*********************@neverbox.com> wrote in message news:<iw*******************@newsread2.news.pas.ear thlink.net>...
Peter Drese wrote:
Can somebody please tell me of what type the following c-statements are?


Statements do not have types. <snip>


Expression statements are evaluated as void expressions. So, in a
sense, the answer is 'void' in all the expression statements in
question. ;)

--
Peter
Nov 14 '05 #10
"Peter Drese" <pd****@yahoo.de> wrote in message news:<bt**********@online.de>...
You wouldn't want us to do your homework for you, would you? This smells
suspiciously like it.


I'm sorry if you think so. Unfortunatly it is not my homework. In about
three weeks I have to write an exam at university about this stuff. I tried
to solve the exercise a couple of times but I'm not sure about my solutions.
If you want, I can post them but I don't want to influence anybody!


Post what you've got, with an explanation of which answers you are
doubtful about and why, and you'll be much more likely to get some
help. I don't understand what you mean by 'influencing people'. Your
answers are either right or wrong. If they're wrong you'll be told so.
Your answers won't influence whether or not your answers are right.
Nov 14 '05 #11

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

Similar topics

5
by: Lars Plessmann | last post by:
I have a problem with typecast methods. Here is a setter of an object: function setKind($kind) { if (is_int((int)$kind) and (strlen($kind)<=6)) { $this->kind = $kind; return true;
1
by: masood.iqbal | last post by:
I have a few questions regarding overloaded typecast operators and copy constructors that I would like an answer for. Thanks in advance. Masood (1) In some examples that I have seen...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
11
by: Manikandan | last post by:
Hi, I am using the following snippet to compare an object with integer in my script. if ( $forecast < 4 ) { I got the "segmentation fault" error message when i executed this script in CLI....
5
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or...
17
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
1
by: skumar22 | last post by:
when I typecast a float to an int. Does the compiler allocate an additional space? for eg if I do something like. float pi = 3.14; int i = (int) pi; then an additional space is created for...
3
by: ryan.gilfether | last post by:
I have a problem that I have been fighting for a while and haven't found a good solution for. Forgive me, but my C++ is really rusty. I have a custom config file class: class ConfigFileValue...
1
by: mike3 | last post by:
Hi. I heard that in C++ typecasts are "evil". However, what does one do with this thing?: --- /* Figure out how many digits of fraction we'll get. * We add 1 to the lengths of a and b to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: 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: 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.