Friday, June 28, 2013

Anonymous Unions in C++

Unions in C++ are special type of classes. We can declare member functions and variables with in the union in c++ (all 'C' features of union remain same). 
But in the unions all the data members share the same memory location.

    Union members are public by default as like structures.

     Anonymous unions are the special type unions with the no name and so we can not create object for that union. All the member data in the anonymous unions share same memory location. We can directly access the these members without any dot operator with in the block where these unions declared. 

Monday, May 27, 2013

Qt QML Introduction and Simple Example Program



QML is declarative language used to develop user interface, is a part of the Qt Quick module. Qt Quick consists of set of technologies including Qml, C++ API's for integrating Qml with Qt application, Qt creator IDE, rum time support.
Qt Quick module comes with the Qt with 4.7 or later versions.

Qml we use elements to draw something on the screen(output) like text, image, rectangle etc.Every element in the qml is like a object. We cal also implement javascript code in side the qml file. Item is the base type for the all the elements.

To start a Qml Application we need to import Qt Quick module with version in the beginning of the every qml file, because the elements we are going to use included in this module. For example the following element displat a rectangle.
Import QtQuick 1.0
Rectangle {
    id: rect
    width: 300
    height: 300
    color: "red"
}

Friday, January 25, 2013

What is the sizeof array type when passed as a function argument?

Sizeof() operator is used to find out the no. of memory bytes occupied by any datatype i.e. it will calculate the size of the given datatype. So if we pass a variable called i of type int, it will give output as 4 bytes, or if we pass a array type say arr which contains declaration as int arr[10] , it will give 40 as output.

We generally use sizeof() operator on array type to find out the number of elements an array contain by dividing the sizeof array by oth element of array (or any element).. The following program will illustrate this

#include<stdio.h>
int main()
{
    int arr[10],s;
    s=sizeof(arr)/sizeof(arr[0]);
    printf("sizeof arr %d\n",sizeof(arr));
    printf("no. of elements of arr %d\n",s);
    return 0;
}

Here the problem is what is the size of the array type in function when we pass it as a argument. This is something different because when we pass array as an argument, the array type decays to pointer. So we can't calculate the no.of elements in the function. This is described by the following program.