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

about array declare with parenthesis mark

#include <stdio.h>

int
main(void)

{
int s[3] = { 1, (3,2), (6, 5, 4)};

printf ("%d %d %d", s[0], s[1], s[2]);

}
~
~
>a.out
1 2 4

this means the last one within the parenthesis mark will works ,
what about others ?
what happened and why .
I want to know ...
it's a part of language or depend on implement ?

Jul 13 '07 #1
3 1311
anson said:
#include <stdio.h>

int
main(void)

{
int s[3] = { 1, (3,2), (6, 5, 4)};

printf ("%d %d %d", s[0], s[1], s[2]);

}
~
~
>>a.out
1 2 4

this means the last one within the parenthesis mark will works ,
what about others ?
what happened and why .
I want to know ...
it's a part of language or depend on implement ?

See page 62 of Kernighan and Ritchie's "The C Programming Language", 2nd
edition.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 13 '07 #2
In article <11**********************@o11g2000prd.googlegroups .com>,
anson <kz****@gmail.comwrote:
>#include <stdio.h>
>int
main(void)
>{
int s[3] = { 1, (3,2), (6, 5, 4)};
>printf ("%d %d %d", s[0], s[1], s[2]);
>}
>>a.out
1 2 4
>this means the last one within the parenthesis mark will works ,
what about others ?
what happened and why .
You used the "comma" operator, which evaluates each expression
in turn discarding each value except the last.
--
Prototypes are supertypes of their clones. -- maplesoft
Jul 13 '07 #3
On Fri, 13 Jul 2007 06:48:02 -0000, anson <kz****@gmail.comwrote in
comp.lang.c:
#include <stdio.h>

int
main(void)

{
int s[3] = { 1, (3,2), (6, 5, 4)};

printf ("%d %d %d", s[0], s[1], s[2]);

}
~
~
a.out
1 2 4

this means the last one within the parenthesis mark will works ,
what about others ?
what happened and why .
I want to know ...
it's a part of language or depend on implement ?
Actually this code is not valid C under versions of the C standard
earlier than 1999. It is valid under C99 and later, but it would not
be if the array 's' was defined with static storage duration.

All objects with static storage duration under all versions of the C
standard, and all aggregate objects prior to C99, must be initialized
with constant expressions. And the comma operator is not allowed in
constant expressions.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jul 13 '07 #4

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

Similar topics

3
by: Mark A Framness | last post by:
Greetings, I am working on a project and we need to write a conversion script to initialize a new field on a table. The number of records on this table is on the order of millions so routine...
4
by: Mark Hannon | last post by:
I am trying to initialize an array only once so it can be seen & used by any functions that need it. As I understand it, if a variable is declared by itself outside of any functions, its scope is...
5
by: dam_fool_2003 | last post by:
Hai, I studied that the array size is fixed. But I come across a word called "variable length array". Is it possible to change the array size? So I tried the following: #include<stdio.h>...
7
by: Rano | last post by:
/* Hello, I've got some troubles with a stupid program... In fact, I just start with the C language and sometime I don't understand how I really have to use malloc. I've readden the FAQ...
1
by: Sharon | last post by:
I have a delegate definition: public delegate void SomeEventHandler(object obj); To make an instance of it it’s easy: public class myClass { public event SomeEventHandler handler; } But,...
3
by: mark | last post by:
When I declare an array as double(,) then try to use it I get an error: "Object reference not set to an instance of an object." I have found that I can redim the array and all is well. Is my...
4
by: mark | last post by:
(windows app not web) I have a procedure to populate a given datagrid (Datagrid1) with a dataset from an indexed data connection. It works: Globals: Dim FileName1 As String Dim DS As...
7
by: Ying | last post by:
I have problems to access a member in an array of pointers to structure. I declare the following structure struct { char name; float mark; }*rec; I would like to put data to rec. ...
7
by: Ming | last post by:
for the following code, why it uses $method = 'examples.getStateName'; instead of $method = 'getStateName'; or $method = 'examples.getStateName()' What does "example" here mean? Thanks <?php...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.