Skip to main content

Posts

WAP to accept number of seconds from the user and convert it into number of hours, minutes and seconds

 

WAP to swap two values without using any third value

Cascading of I/O operator

  Cascading of Output Operator If we use output operator '<<' (aka stream insertion operator or put to operator) multiple times in a single 'cout' statement then it is called cascading of output operator. It can be done 255 times max. Cascading of Input Operator If we use input operator '>>' (aka stream extraction operator or get from operator) multiple times in a single 'cin' statement then it is called cascading of input operator. 

Data Type Modifiers

 As the name suggests, data type modifiers are used with fundamental data types to modify the length of data that a particular data type can hold. Following 4 datatype modifiers are available in C++: Signed Unsigned Short Long

Data Types

Datatype defines the type of value which we store in the variable.  They are a means to define the type of data and associated operation of handling it. There are 3 major data types: Fundamental Datatype : The datatypes which are not composed of other datatype are called as fundamental datatypes. Example: Integer Character Floating Point Double Floating Point Boolean Void Derived Datatype The datatypes derived from the fundamental datatypes are called as derived datatypes. Example: Function Array Pointer Reference User-defined Datatype These are defined by the user itself. Example: Class Structure Union Enumeration Typedef enum (enumeration) Enumerated means that all values are listed. Example :  Instead of writing 3 integer constants separately like : const int START = 0; const int PAUSE = 1; const int GO = 2; We can write : enum { START, PAUSE, GO} ; enum week_days { sun, mon, tue, wed, thur, fri, sat } ;                     ...

Rules for naming convention of a variable :

1. First letter of a variable name cannot be a digit. Example :  5 id  ✖ id5   ✔ i5d   ✔ 2. Special characters are not allowed within the variable name except an underscore _ Example: rollno.    ✖    //full stop is not allowed roll no    ✖   //space is not allowed _rollno   ✔ 3. Keywords are not allowed within the variable name Example :  void   ✖      

Variables / Identifiers / Literals (Constants)

Variables These are the memory location which can store a value. As the name suggests, the value of a variable can vary during the whole program. In other words, variables are named storage locations whose value can be manipulated during program run. Example:  a = 5;  ✔ 5 = a;  ✖ a = a + 2; a = a + 10; Identifiers Name of variable, function, array, class etc created by the programmer are called as identifiers. Constants Data items that never change their value during a program run. integer constant character constant floating constant string-literal