CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: C++ syntax

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    C++ syntax

    In this line of C++ code ;

    Code:
     int permissions = (mode == QSharedMemory::ReadOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS);
    what does the question mark mean and the colon mean

  2. #2
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: C++ syntax

    It´s the ternary operator, it´s syntax is "exp ? A : B". When the exp evaluates to true, its return value is A, else it´s B.
    - Guido

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: C++ syntax

    Quote Originally Posted by aamir121a View Post
    In this line of C++ code ;

    Code:
     int permissions = (mode == QSharedMemory::ReadOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS);
    what does the question mark mean and the colon mean
    Think of it like
    Code:
    if(mode == QSharedMemory::ReadOnly)
        permissions = FILE_MAP_READ;
    else
        permissions = FILE_MAP_ALL_ACCESS;

  4. #4
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: C++ syntax

    thank you all as always you have been most helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured