?
Solved

c programing

Posted on 2003-03-29
19
Medium Priority
?
202 Views
Last Modified: 2010-04-17
hi experts,
can we declare a variable inside for loops or others such.
eg. for(int i=0;i<=100;i++)

i m sandip.
0
Comment
Question by:sandipmurmu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 4
  • +3
19 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 8231686
What do you mean/

mlmcc
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 8232400
Nope, that doesn't work in c, but has been introduced in c++ and is generally referred to as on-the-fly variable declaration.

.f
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8232420
for(int i=0;i<=100;i++)  works just fine in C.

mlmcc
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Accepted Solution

by:
ozo earned 80 total points
ID: 8232610
It doesn't work in strictly conforming ANSI Standard X3.159-1989 C, but because it works in C++ some C compilers will recognise it
0
 
LVL 5

Expert Comment

by:burtdav
ID: 8235361
It is allowed in the newer 1999 ISO C standard (known as C99).
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8236377
Strictly speaking, it won't work in C. It will work in C++, though. C++ allows you to declare variables anywhere in your program so that you don't have to go through the process of declaring everything right at the start of the function, but at your ease, you can just declare more and more variables anywhere whenever you need them.  

mlmcc said that it'll work on C, but probably he's not tried it in a pure C compiler. C++ compilers will allow it. However, I guess that if you save the file with a .C extension (instead of .CPP), then even a C++ compiler will report an error.

Mayank.
0
 
LVL 5

Expert Comment

by:burtdav
ID: 8237709
Can I disagree, Mayank? As I just stated above, it is valid in C99, which is "pure C".
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8237916
Checked it on http://home.tiscalinet.ch/t_wolf/tw/c/c9x_changes.html

You're right. Its allowed.

Mayank.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 8238525
You will most likely have to set compiler switches though, to enable compilation conforming with c99 standard.

.f
0
 

Expert Comment

by:CleanupPing
ID: 9446667
sandipmurmu:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 9447759
I believe I answered it.

mlmcc
0
 
LVL 5

Expert Comment

by:burtdav
ID: 9448640
(Sorry mlmcc) I think fl0yd, ozo, myself (burtdav) and mayankeagle were on the right track. There's definitely an A to be given between us. I'd be happy to take the points if none of the other 3 want them.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 9449497
As long as the points don't go to mlmcc, I'm happy with anything. My suggestion would be to split points between burtdav (first one to draw attention to the evolution of c) and mayankeagle for the helpful link.

.f
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9472042
Thank you. My recommendation was also to split points between burtdav, ozo, fl0yd and mayankeagle.
0
 
LVL 5

Expert Comment

by:burtdav
ID: 9477062
I think it'd be classy to split 20 points 4 ways.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 9479370
Then again, points are nothing but a side effect. In essence choosing answers will make it easier for others searching through PAQ's finding an answer quickly.

.f
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9490526
>> it'd be classy to split 20 points 4 ways

if its an A grade, then its still 20 points to each. Anyways, hardly matters!
0
 
LVL 5

Expert Comment

by:burtdav
ID: 9511580
Well chosen, AnnieMod.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question