Exforsys

Free Training

Is this Program Correct

This is a discussion on Is this Program Correct within the C and C++ forums, part of the Programming Talk category; I have a doubt about typecasting in C. I have the below code written in my program #include <stdio.h> main() ...

Go Back   Exforsys > Programming Talk > C and C++

Exforsys.com


C and C++ C and C++

Reply

 

LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 05-15-2007, 06:29 PM
Senior Member
 
Join Date: Apr 2006
Posts: 153
cyrus is on a distinguished road
Is this Program Correct

I have a doubt about typecasting in C. I have the below code written in my program

#include <stdio.h>
main()
{
int x = 101;
char y;
y = x;
}

Is the above code correct that will C do automatic typecasting as assumed above in my code or do programmers have to do typecasting explicitly? If so I have to change my code. Kindly clarify my doubt?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-18-2007, 03:04 PM
Senior Member
 
Join Date: Apr 2006
Posts: 162
sammy is on a distinguished road
This will not get automatically typecast as you have mentioned in your program. Automatic typecasting takes place in C but not as you have mentioned. Say for instance you have placed a variable x in a if statement then depending on the value of variables as 0 or 1 the conditional takes up status as false or true respectively. Whenever data type need to be changed you must use explicit typecasting in C programming language with the data type mentioned in brackets.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 06-15-2004 06:00 AM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 06-01-2004 06:01 AM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit Tech FAQ 0 06-01-2004 06:00 AM
comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) Steve Summit Tech FAQ 0 05-15-2004 06:00 AM
Apple II Csa2 FAQs: Telecom Hardware & Transfers, Part 20/25 rubywand@swbell.net Tech FAQ 0 04-04-2004 07:29 AM


All times are GMT -4. The time now is 03:15 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright 2004 - 2009 Exforsys Inc. All rights reserved.