Monday, January 13, 2014

C - Structure. What is structure in C Language?

A structure is a collection of one or more variables, possibly of different types, grouped together under a single name for convenient handling. Structures help to organize complicated data, particularly in large programs, because they permit a group of related variables to be treated as a unit instead of as separate entities.

The keyword struct introduces a structure declaration, which is a list of declarations enclosed in braces. An optional name called a structure tag may follow the word struct (as with point here). The tag names this kind of structure, and can be used subsequently as a shorthand for the part of the declaration in braces.

The variables named in a structure are called members. A structure member or tag and an ordinary variable can have the same name without conflict, since they can always be distinguished by context. Furthermore, the same member names may occur in different structures, although as a matter of style one would normally use the same names only for closely related objects.

Uses of C structures:

    1. 1. C Structures can be used to store huge data. Structures act as a database.
    2. 2. C Structures can be used to send data to the printer.
    3. 3. C Structures can interact with keyboard and mouse to store the data.
    4. 4. C Structures can be used in drawing and floppy formatting.
    5. 5. C Structures can be used to clear output screen contents.
    6. 6. C Structures can be used to check computer’s memory size etc.

Difference between C variable, C array and C structure:

    • 1. A normal C variable can hold only one data of one data type at a time.
    • 2. An array can hold group of data of same data type.
    • 3. A structure can hold group of data of different data types
    • 4. Data types can be int, char, float, double and long double etc. 
Datatype

C variable

C array

C structure

Syntax Example Syntax Example Syntax Example
int int a a = 20 int a[3] a[0] = 10
a[1] = 20
a[2] = 30
a[3] = ‘\0′
struct student
{
int a;
char b[10];
}
a = 10
b = “Hello”
char char b b=’Z’ char b[10] b=”Hello”

Below table explains following concepts in C structure.

    1. 1. How to declare a C structure?
    2. 2. How to initialize a C structure?
    3. 3. How to access the members of a C structure?
Type Using normal variable Using pointer variabe
Syntax struct tag_name
{
data type var_name1;
data type var_name2;
data type var_name3;
};
struct tag_name
{
data type var_name1;
data type var_name2;
data type var_name3;
};
Example struct student
{
int  mark;
char name[10];
float average;
};
struct student
{
int  mark;
char name[10];
float average;
};
Declaring structure variable struct student report; struct student *report, rep;
Initializing structure variable struct student report = {100, “Mani”, 99.5}; struct student rep = {100, “Mani”, 99.5};  report = &rep;
Accessing structure members report.mark
report.name
report.average
report  -> mark
report -> name
report -> average

 Example program for C structure:

           This program is used to store and access “id, name and percentage” for one student. We can also store and access these data for many students using array of structures. You can check “C – Array of Structures“ to know how to store and access these data for many students.

#include <stdio.h>
#include <string.h>

struct student
{
           int id;
           char name[20];
           float percentage;
};

int main()
{
           struct student record = {0}; //Initializing to null

           record.id=1;
           strcpy(record.name, "Caroline");
           record.percentage = 86.5;

           printf(" Id is: %d \n", record.id);
           printf(" Name is: %s \n", record.name);
           printf(" Percentage is: %f \n", record.percentage);
           return 0;
}

Output:

Id is: 1
Name is: Caroline
Percentage is: 86.500000

Example program – Another way of declaring C structure:

           In this program, structure variable “record” is declared while declaring structure itself. In above structure example program, structure variable “struct student record” is declared inside main function which is after declaring structure.
#include <stdio.h>
#include <string.h>

struct student
{
            int id;
            char name[20];
            float percentage;
} record;

int main()
{

            record.id=1;
            strcpy(record.name, "Raju");
            record.percentage = 86.5;

            printf(" Id is: %d \n", record.id);
            printf(" Name is: %s \n", record.name);
            printf(" Percentage is: %f \n", record.percentage);
            return 0;
}

Output:

Id is: 1
Name is: Raju
Percentage is: 86.500000

C structure declaration in separate header file:

In above structure programs, C structure is declared in main source file. Instead of declaring C structure in main source file, we can have this structure declaration in another file called “header file” and we can include that header file in main source file as shown below.
Header file name – structure.h

Before compiling and executing below C program, create a file named “structure.h” and declare the below structure.

struct student
{
int id;
char name[20];
float percentage;
} record;
Main file name – structure.c:

           In this program, above created header file is included in “structure.c” source file as #include “Structure.h”. So, the structure declared in “structure.h” file can be used in “structure.c” source file.
// File name - structure.c
#include <stdio.h>
#include <string.h>
#include "structure.h"   /* header file where C structure is
                            declared */

int main()
{

   record.id=1;
   strcpy(record.name, "Raju");
   record.percentage = 86.5;

   printf(" Id is: %d \n", record.id);
   printf(" Name is: %s \n", record.name);
   printf(" Percentage is: %f \n", record.percentage);
   return 0;
}

Output:

Id is: 1
Name is: Raju
Percentage is: 86.500000


Wednesday, January 8, 2014

What Is The Difference Between 32-bit & 64-bit Windows?

“What is the difference between a 32-bit and 64-bit Windows operating system?” Most of you are running Windows XP or Vista in its 32-bit iteration. But as hardware gets cheaper, people are curious as to what the 64-bit operating system has to offer. First let’s see if we can grasp the difference between 32- and 64-bit.

Think of your computer as a series of tubes that can either be 32 or 64 bits wide. When you have the smaller 32-bit size, there is more potential for bottlenecks to occur. Bottlenecks slow down your system because one process has to wait for another to finish before it can begin. But if you want to have 64-bit wide tubes, your computer needs to be thinking in 64-bit so your software and hardware all need to support 64-bit.

If you do not know the difference between 32-bit and 64-bit, I would have told you in the past that you are running a 32-bit version of Windows. But now with Windows 7 I am seeing more and more 64-bit operating systems shipped by default without the end users knowledge. Don’t get me wrong, a 64-bit system is better but you also need to be running 64-bit programs and have a 64-bit processor or else all the trouble of setting up the 64-bit operating system would be worthless.

On a 32-bit operating system, you are restricted to a maximum of 3 gigabytes of RAM. On a 64-bit operating system, you really do not have a limit. Let’s look at Wikipedia and find out the maximum amount of RAM for a 64-bit operating system:

264 addresses, equivalent to approximately 17.2 billion gigabytes, 16.3 million terabytes, or 16 exabytes of RAM.
That is a huge amount of RAM! Normally when you exhaust your physical RAM on a 32-bit system, it has to use virtual memory or hard disk space to pick up the slack. On a 64-bit system, you can install as much RAM as you can to cover your overhead. From here on, 32-bit operating systems will be referred to as x86 and 64 bit operating systems as x64. You can tell what you are running by right clicking on My Computer and choosing Properties.  Below is a shot of a 64-bit machine using 12GB of memory.

 
And in this shot, we see a 32-bit machine trying to use 7GB of RAM.. Not going to happen!
 

If you are running 3D modeling systems or AutoCAD systems, you can benefit from a x64 bit architecture but remember, you need to be running ALL x64 applications, print drivers and anything else you are setting up on your system to realize its full potential. Not all programs have been created for x64 yet and you will find yourself installing applications to your Program Files x86 directory. On a x64 machine, you will have two Program File directories — one for 32-bit and one for 64-bit applications.
So after reading through that and you still want to run a x64 operating system, you will need to make sure your processor supports x64. Most new servers and new computers bought this year or beyond will support x64 but you will still need to check. Here are some facts you should know:
  • Almost all new servers sold within the last two years from AMD or Intel will have x64 capability.
  • Most mid- to high-end desktop processors from AMD or Intel within the last year have x64 capability.
  • Some higher-end Semprons have x64; lower-end Semprons do not.
  • No AMD Durons have x64.
  • All AMD Opteron processors have x64.
  • All AMD X2, FX, and Athlon64 chips have x64.
  • All Intel Pentium D and Celeron D chips have x64.
  • All AMD Turion notebook processors have x64.
  • All Intel Core 2 processors (mobile, desktop, and server) have x64.
  • No Intel Core Duo notebook processors have x64
  • No Intel Pentium M notebook processors have x64.
If you are still not sure if your processor can support x64 check out GRC’s SecurAble and let them help you figure it out! You might also want to check out Mahendra’s post How To Choose Between 32-bit & 64-bit Windows 7 Operating Systems.

If you are running a server that has all its hardware and software certified for x64, then you should install the 64-bit version but beware of device drivers and any 32-bit environments because if I used the word difficult, it would be an understatement!


Who are you? Who am I?

Psychologists Say :
  1.  1.  If A Person Laughs Too Much, Even At Stupid Things, He Is Lonely Deep Inside.
  2.  2. If A Person Sleeps A Lot, He Is Sad.
  3.  3. If A Person Speaks Less, But Speaks Fast, He Keeps Secrets.
  4.  4. If Some One Can't Cry, He Is Weak.
  5.  5. If Some One Eats In An Abnormal Manner, He Is Tensed.
  6.  6. If Some One Cries On Little Things, He Is Innocent & Soft-Hearted.
  7.   7. If Some One Becomes Angry Over Silly Or Petty (Small) Things, It Means He Needs Love......


  Try To Understand People. We are living in such a World, where Artificial Lemon Flavour is used for Welcome Drink &  Real Lemon is used in Finger bowl.


............is my number ?

Saturday, January 4, 2014

What is Compiler ?

Definition of Compiler :

  1. A computer program which reads source code and outputs assembly code or executable code is called compiler.
  2. A program that translates software written in source code into instructions that a computer can understand Software used to translate the text that a programmer writes into a format the CPU can use.
  3. A piece of software that takes third-generation language code and translates it into a specific assembly code. Compilers can be quite complicated pieces of software.

Compiler Overview :

Consider process of Executing Simple C Language Code –

We have opened C Code editor and wrote simple C Program , Whenever we try to compile code and try to execute code our code is given to the compiler.
int main()
{
printf("Hello");
return(0);
}
Now our main intention is to convert program into lower level language which can be read by Machine. Compiler have different phases , and program undergoes through these 6 phases. After Passing through all the compilation Phases our code is converted into the machine level language code which can be read by machine.