Showing posts with label keyword. Show all posts
Showing posts with label keyword. Show all posts

Wednesday, September 12, 2012

Program to illustrate 'typedef' keyword

#include <iostream>
using std::cout;
using std::endl;

typedef float FLOAT32;
typedef double FLOAT64;     //
By using typedef Keyword we can make alias of datatypes
typedef unsigned int U32;    //it is something like macro

int main()
{
    U32 bigint = 23433;
    FLOAT32 myFloat = 6.6;
    FLOAT64 myDouble = 34343.3;
   
    cout << "  bigint: " << bigint;
    cout << "\n myFloat: " << myFloat;
    cout << "\nmyDouble: " << myDouble;
}


what is typedef:
typedef is a keyword in the C and C++ programming languages. The purpose
of typedef is to assign alternative names to existing types

what is the use of typedef keyword:

1) it provides a means to make a program more portable. Instead of having to
    change a type everywhere it appears throughout the program's source 

    files, only a single typedef statement needs to be changed.
2) A typedef can make a complex declaration easier to understand. 


By using typedef Keyword we can make alias of datatypes

Monday, April 2, 2012

Program to illustrate 'const' keyword

The const keyword is used to modify a declaration of a field or local variable. It specifies that the value of the field or the local variable cannot be modified.

// program to illustrate const keyword
// using  c#


using System;

public class ConstTest
{
    class MyClass
    {
        public int x;
        public int y;
        public const int c1 = 5;
        public const int c2 = c1 + 5;
       
        public  MyClass(int p1, int p2)
        {
            x = p1;
            y = p2;
        }
    }
   
    public static void Main()
    {
        MyClass mC = new MyClass(11, 22);
        Console.WriteLine ("x = {0}, y = {1}", mC.x, mC.y);
        Console.WriteLine ("c1 = {0}, c2 = {1}", MyClass.c1, MyClass.c2);
    }
}

OUTPUT:
x = 11, y = 22
c1 = 5, c2 = 10

Wednesday, February 8, 2012

The list of 'keyword' you must known

  1. friend -- Grant non-member function access to private data.
  2. inline -- Optimize calls to short functions.
  3. namespace -- Partition the global namespace by defining a scope.
  4. new -- Allocate dynamic memory for a new variable.
  5. static -- Create permanent storage of a variable.
  6. template -- Create generics functions.
  7. this -- A pointer to the current object.
  8. using -- Import complete or partial namespace.
  9. virtual -- Create a function that can be overridden by a derived class.