BrainDump
  Home arrow BrainDump arrow C: More Operators and Arrays
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

C: More Operators and Arrays
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-02-19

    Table of Contents:
  • C: More Operators and Arrays
  • Bitwise Operators
  • Arrays
  • Two-Dimensional Arrays
  • Commenting on Your Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    C: More Operators and Arrays


    (Page 1 of 5 )

    In our last article we left off discussing some of C's Operators and how to use them. We will pick up on the same subject in this article, and cover arrays as well. As always, there is a lot to cover, so let's get to it.

    Conditional OR Ternary Operator

    Our good buddy the conditional operator is made up of two symbols: the question mark (?) and the colon(:). Consider the following:

      mine = 100;

      yours = 200;

      ours = (mine > yours) ? mine : yours

    In this example, the variable ours will be assigned the value of the variable yours, or 200. This occurs because the expression (mine > yours) is false. Had it been true, then the value of ours would have been the value of the variable mine, or 100.

    Here is an example:


    #include <stdio.h>

    #include <stdlib.h>


    void main()

    {

    int mine,yours,bigger;

    printf ("Input my number and your number : ");

    scanf_s("%d %d",&mine, &yours);

    bigger = mine > yours ? mine : yours;

    printf("The largest of two numbers is %d \n", bigger);

    }

    This code asks the user for two numbers. It stores the first number in the variable mine, and the second in the variable yours. Next it asks if mine is greater than yours. If so, bigger will get the value of the mine variable. If not, it will get the value of the yours variable. Finally it prints some text and appends the value of the variable bigger.

    If the user had entered the numbers 20 and 50, the result would be:

      Input my number and your number: 20 50

      The largest of the two numbers is 50

    More BrainDump Articles
    More By James Payne


       · Thanks for dropping by to read my article on C Operators and Arrays. In this episode...
     

    BRAINDUMP ARTICLES

    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection
    - Advanced Firebug Techniques in Windows XP Ho...
    - Editing CSS with Firebug in Windows XP Home
    - Using Firebug in Windows XP Home
    - Migrating to Exchange Server 2007
    - Using System Restore on a Non-Bootable PC
    - Finding Logged on Users and More Scripting S...
    - Developing Macro Commands in MS Excel





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek