element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Code Exchange
  • Technologies
  • More
Code Exchange
Forum Redundant parathensis in C
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Code Exchange to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 26 replies
  • Answers 4 answers
  • Subscribers 51 subscribers
  • Views 2118 views
  • Users 0 members are here
  • Code Exchange
  • redundant
  • conditional tricky writing style
  • if else construct
  • paranthesis
Related

Redundant parathensis in C

dr.akshay_1980@yahoo.com
dr.akshay_1980@yahoo.com over 9 years ago

Hi,

Out of curiosity and experimenting with ANSI C constructs ,I would like to know any means by which we can ignore the empty braces for the conditional statements in C programming??? Does C allow us to do this.

 

Refer below the sample C code for discussion

 

 

int main()

{

     if()             /// there should no error while writing this, empty parathensis..

{

     printf("your if  is without parameters...");

}

else

{

    printf("if block ignored....");

}

return 0;

}

 

 

How to implement the above code in C successfully without any errors(compile time/Run time)????? By any means I want to implement above style.

 

 

Thanks in advance....

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 9 years ago in reply to clem57 +2
    It looks like another interview/college homework type question (they do ask odd questions sometimes). Much like this one: If-Else construct in C language-hello world As you say, nothing for any real practical…
  • amgalbu
    amgalbu over 9 years ago +1 suggested
    According to c grammar, you need to type a boolean expression. So there is no way to create an if without condition
  • amgalbu
    amgalbu over 9 years ago in reply to D_Hersey +1
    @akshay dharma is asking if it is possibile to uae empty braces after a if keyword. That's noto possibile imho. Btw true and false are c++ keywords, and are not allowed in ANSI c (aka c90)
  • amgalbu
    0 amgalbu over 9 years ago

    According to c grammar, you need to type a boolean expression. So there is no way to create an if without condition

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • D_Hersey
    0 D_Hersey over 9 years ago in reply to amgalbu

    if(true) works, in the sense that the following action would always happen, we just need a resolvable condition, not a conditional.  if(false) doesn't, in the sense that the following action would never happen, because false is an alias for zero.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • D_Hersey
    0 D_Hersey over 9 years ago

    This can confuse beginners because assignment, when successful, resolves true. '=' for assignment, IIRC, == for comparison.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 9 years ago

    What sense would you expect to ask a question with no facts? C is just logic! A null condition has no context,

    But look at Go and a for loop can have ( ) and acts as a forever loop if you like because the language defines it..

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • D_Hersey
    0 D_Hersey over 9 years ago

    comparison looks like a dyadic infix function that resolves t/f symbolized by '=.'  any function that returns an integer can be used inside the parentheses

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • D_Hersey
    0 D_Hersey over 9 years ago

    so, it doesn't do anything, but if(1) works

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • shabaz
    0 shabaz over 9 years ago in reply to clem57

    It looks like another interview/college homework type question (they do ask odd questions sometimes).

    Much like this one: If-Else construct in C language-hello world

    As you say, nothing for any real practical reason.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • amgalbu
    0 amgalbu over 9 years ago in reply to D_Hersey

    @akshay dharma is asking if it is possibile to uae empty braces after a if keyword. That's noto possibile imho.  Btw true and false are c++ keywords, and are not allowed in ANSI c (aka c90)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gadget.iom
    0 gadget.iom over 9 years ago in reply to shabaz

    shabaz wrote:

     

    Much like this one: If-Else construct in C language-hello world

    It immediately sounded familiar...

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • D_Hersey
    0 D_Hersey over 9 years ago in reply to amgalbu

    I recommend C++, haven't used C in decades.  Go Bjarne!!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube