473,382 Members | 1,445 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,382 software developers and data experts.

increment in if statement

Hi All,

My Aim here is to increment lArray whether control goes inside if
statement or not. Is this a portable step and C guarantees that lArray
must be incremented?

Thanks,
Nishu
#include<stdio.h>

int main(void)
{
int i = 7;
int array[] = {0,1,1,0,1,1,0};
int* lArray;

lArray = array;

while(i--)
{
if(*lArray++) /* Is this a portable step? */
{
printf("enters in if loop\n");
}
}
return 0;

}

Mar 1 '07 #1
2 5923
On Mar 1, 9:50 am, "Nishu" <naresh.at...@gmail.comwrote:
Hi All,

My Aim here is to increment lArray whether control goes inside if
statement or not. Is this a portable step and C guarantees that lArray
must be incremented?

Thanks,
Nishu

#include<stdio.h>

int main(void)
{
int i = 7;
int array[] = {0,1,1,0,1,1,0};
int* lArray;

lArray = array;

while(i--)
{
if(*lArray++) /* Is this a portable step? */
{
printf("enters in if loop\n");
}
}
return 0;

}
Yes. As far as I know, you're safe.

Mar 1 '07 #2
Nishu wrote, On 01/03/07 07:50:
Hi All,

My Aim here is to increment lArray whether control goes inside if
statement or not. Is this a portable step and C guarantees that lArray
must be incremented?

#include<stdio.h>

int main(void)
{
int i = 7;
int array[] = {0,1,1,0,1,1,0};
Apart from the fact I would not write code like this, I would rearrange
the above two declarations to
int array[] = {0,1,1,0,1,1,0};
int i = (sizeof array) / sizeof *array;
Then you don't have to change the initialisation of i if you change the
size of the array.
int* lArray;

lArray = array;

while(i--)
{
if(*lArray++) /* Is this a portable step? */
Yes, it is completely portable, and almost equivalent to:
lArray++;
if (*(lArray-1))

I say almost because of sequence points which would be more important
with a more complex expression.
{
printf("enters in if loop\n");
}
}
return 0;

}
--
Flash Gordon
Mar 1 '07 #3

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

Similar topics

9
by: Mark Turney | last post by:
I was reading "Practical C++ Programming" yesterday, and it mentioned that the order of execution for post-increment and post-decrement operators was ambiguous. I had previously learned that a...
15
by: Robert Swan | last post by:
I'd like to know why the following program outputs 1, and not 0. #include <iostream> class a { int v; public: a():v(0){} a& operator++(int) { v++;
11
by: Randell D. | last post by:
Folks, I have a table of addresses and a seperate table with contact names - All addresses tie to one or more names - I would like to keep track of the number of names 'belonging' to an address...
2
by: Tom | last post by:
I am trying to store information into a table that has an auto increment field. There is currently no data in the table. Using the code below I cannot insert data into the table. I get an error...
13
by: kailasam | last post by:
Hello, Iam having a doubt. Which is more efficient post increment or Pre increment? I have read that preincrement is efficient than Post increment. Iam not able to think how it is? For an...
3
by: George Ter-Saakov | last post by:
What is the purpose of having Interlocked.Increment if it does not work with variable declared as volatile. Here is my problem, Interlocked.Increment increments the variable in thread safe...
2
by: alexs | last post by:
Chaps, I'm starting to play with db2 V9.1 and am writing a stored procedure to manage accounting records from oiur RADIUS server. I've got an XML aware table with an auto increment primary...
11
by: divya_rathore_ | last post by:
The code: int aaa = 100; printf("%d %d %d\n", --aaa, aaa, aaa--); printf("%d\n", aaa); prints: 99 100 100 98
2
by: vinnie | last post by:
what's the difference between " i++ " and " ++i " ? Thanks
5
by: simudream | last post by:
//hi maybe helpful others can look at this code and //tell me why the class code won't behave like //intrinsic types with post and pre increment //Version: 1.00 #include <iostream> using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.