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

Is it possible to initialize values to a single variable using '( )'

1
int a;
a=(32,3,3,4,77,48);

what is the meaning of above initialization?
can you please help me?
Jun 12 '12 #1
3 1720
weaknessforcats
9,208 Expert Mod 8TB
The variable is initialized using a list involving the comma operator.
=(32,3,3,4,77,48);

So the variable is initialized to 32, then changed to 3, then changed to 3 again, then changed to 4, then changed to 77 and finally changed to 48.

This has to be from some class or textbook.
Jun 12 '12 #2
I would rather say that the comma operator evaluate each operation one after each other. As you use parenthesis, everything inside is evaluated, then the assignment is done with the last evaluation done inside the parenthesis, i.e 48.

Then only 48 should be assigned to the "a" variable. 32 is evaluated, but since it is only a value nothing is done. The same for 3, 3, 4, 77 and finally 48. 48 being the last operation, it is the value that "gets out the parenthesis". Then a = 48 is evaluated, and 48 is stored into a.

But whatever the way it works, a will have the same value, and if you have a good compiler all of this will be optimized to a = 48.
Jun 14 '12 #3
donbock
2,426 Expert 2GB
To be clear, in my personal opinion you should never write code that looks like this. It looks like a contrived example to demonstrate the more obscure implications of the comma operator.

The only exception I can think of is an entry in The Obfuscated C Contest.
Jun 14 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: steveneng | last post by:
C++ Primer Plus Programming Exercises 4th Ed - Prate Help I'm trying to refresh myself and I'm stuck on this problem (not homework/school related but for personal advancement). 6: Do...
28
by: rajendra.stalekar | last post by:
Hi Folks!!! I have a string let's say "hi" and got to reverse it using just a single variable for swapping, how do I do it? Regards, Rajendra S.
3
by: Gustaf Liljegren | last post by:
I searched for previous answers on this, but couldn't find something fitting. I need advice on how to store decimal numbers with possible null values in memory. The numbers may be negative, so...
4
by: huzz | last post by:
I like to put all the values of an array into a single variable like: networkFiles = "val 1 val 2 val 3 val 4 val 5"; Here is what i am doing, but getting error message: Operator '+'...
12
by: NewToCPP | last post by:
does the default constructor initialize values? I have a class as defined below: class A { int i; char c; int * iPtr;
4
by: nirjhar.oberoi | last post by:
Hi, This is my first post on this group! i am beginner lever C programmer. I am trying to add two numbers or multiply them using a single variable! Your are not allowed to use Unions or any...
1
by: DanubeRS | last post by:
Hi, i am currently facing a problem where i need to write a loop that sorts through a 2d array in VB6 and assign a certain image to pictures that are named incrementally based on the value of that...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.