445,820 Members | 1,142 Online
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

# implicit typecast

 P: n/a 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 Replies

 P: n/a Peter Drese 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

 P: n/a > 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

 P: n/a In article , "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. 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

 P: n/a Clark Cox writes: In article , "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. 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

 P: n/a 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

 P: n/a 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. 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

 P: n/a "Peter Drese" 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 San Diego Supercomputer Center <*> Schroedinger does Shakespeare: "To be *and* not to be" Nov 14 '05 #8

 P: n/a 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

 P: n/a Kevin Goodsell wrote in message news:... Peter Drese wrote: Can somebody please tell me of what type the following c-statements are? Statements do not have types. 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

 P: n/a "Peter Drese" wrote in message news:... 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 discussion thread is closed

Replies have been disabled for this discussion.