C& CPP Tutorials
About C
Program Structure
Running C Program
Variables, constants
Operators
Control Structure
Array
Function
Pointers
Preprocessor
Structure
File
Bitwise Operators
Recursion
 Data Structures
Introduction
Stacks
Queues
Linked List
Sorting 
Searching
 Test Your Skill
Fundamentals
Input and Output
Branching and Looping
Function
Pointers I
Pointers II
Structure and Union
Sample Problems I
Sample Problems II
 Help and Support
C Forum
Source code
C  Yahoo Group
C Compilers
 

Conditional Operator: ? :

Syntax of Conditional operators is 

logical-or-expression ? expression : conditional-expression

The conditional operator (? :) is a ternary operator (it takes three operands). The conditional operator works as follows

  • The first operand is implicitly converted to bool. It is evaluated and all side effects are completed before continuing.

  • If the first operand evaluates to true (1), the second operand is evaluated.

  • If the first operand evaluates to false (0), the third operand is evaluated.

The result of the conditional operator is the result of whichever operand is evaluated — the second or the third. Only one of the last two operands is evaluated in a conditional expression.


 #include<stdio.h>
  void main()
   {
     int a,b;
     printf("Enter value of a);
    scanf("%d",&a);
    printf("Enter value of b);
    scanf("%d",&b);
    (a>b)?printf("%d is big",a):printf("%d is big",b);
    getch();
  }

BITWISE OPERATORS

C has a distinction of supporting special operators known as bitwise operators for manipulation of data at bit level. These operators are used for testing the bits, or shifting them right or left. Bitwise operators may not be applied to float or double. Bitwise operators are 

 Operators

Meaning

&

|

^

<<

>>

~

bitwise AND

bitwise OR

bitwise exclusive OR

Shift left

Shift right

One's complement

 More about bitwise operators

User Defined Type Declaration

C support the feature known as type definition that allows user to define an identifier that would represent an exiting data type. The user defined datatype isentifier can later be used to declare variables. It takes the general form.

typedef type identifier;

Where type refers to an existing data type may belong to any class of type , including the user defined ones. Remember that the new type is 'new' only in name , but not the data type. typedef can not create a new type. Some example of type definition are


 typedef int unit;
 typedef float marks;

Here , unit symbolizes int and mark symbolizes folat. They can be later used to declare variables as follows.


 units batch1, batch2;
 marks name1[50], name2[50];

Bacth1 and batch2 are declare as int variable and name1[50] and name2[50] are declared as 50 element of floating point array variables. The main advantage of typedef is that we can create meaningful data type name for increasing the readability of the program

 Another user-defined data type is enumerated data type provided by ANSI standard. It is defined as follows.


 enum identifier  { value1,value2,....valuen };


The identifier is user -defined enumerated data type which can be used to declare variable that can have one of the value enclosed with in the braces ( known as enumeration constant). After this  we can declare variables to be of this new type as below.
  


 enum identifier v1,v2,...vn.

The enumerated variable v1,v2,..vn can only have one of the following types are valid;


  v1= value3;
  v3= value1;

An example


  enum day { Monday, Tuesday,...,Sunday};
  enum  day week_st, Week_end;

  Weel_st= Monday;
  week_end= Friday;
  if(week_st==Tuesday)
  week_end=Saturday;  


The compiler automatically assign integer digit beginning with 0 to all the enumeration constants that is , the enumeration constant value1 is assign 0, value 1 , and so on. However the automatic assignment can be overridden by assigning values explicitly to the enumeration constant For example


 enum day { Monday=1, Tuesday,...Sunday };

 
Here, the constant Monday is assigned the value of 1. The remaining constants are assigned values that increase successively by 1.

 The definition and deceleration of enumerated variable can be combined in one statement

 
 enum day { Monday,....Sunday} Week_st, Week_end;

Back Next
 

Google