Sunday, December 26, 2010

Compiling C Program Under Unix

To compile the C program under Unix environment. We need C Compiler to compile C program. Some C compilers are cc, gcc and etc., In this cc compiler is available under any environment. To compile:
cc file_name.c
this will compile C program. To run,
./a.out

Example:
cc sample.c

To run this,
./a.out

Another way,
cc -o output_file file_name.c

To run this,
./output_file

Example:
cc -o sampleout sample.c

To run,
./sampleout

Linux Filesystem

As a Linux system boots, the filesystem that becomes available is the top level, or rot filesystem, denoted with a single forward slash(/). The root filesystem /, also known as root directory, shouldn't be confused with the root superuser account or the superuser's home directory, / root. In a installation, the root filesystem could contain nearly everything on the system. As the Linux kernel boots, the partitions are mounted to the root filesystem, and together create a single unified filesystem. Everything on the system that is not stored in a mounted partition is stored locally in the / partition. The mounted filesystem are placed on separate partitions and possibly multiple disk drives. Here is the list of directories the root filesystem contains:

/ (the root directory): Since the only filesystem mounted at the start of the boot process is /, certain directories must be part of it to be available for the boot process. These include:

/bin and /sbin: Contains required system binary programs.

/dev: Contains device files.

/etc: Contains configuration information used on boot.

/lib: Contains shared libraries. These directories are always part of the single / partition.

/boot: This directories holds static files used by the boot loader, including kernel images. On system where kernel development activity occurs regularly, making /boot a partition eliminates the possibility that / will fill with kernel images and associated files during development.

/home: User files are usually placed in a partition. This is often the largest partition on the system and may be located on a separate physical disk or disk array.

/tmp: This directory is often a separate partition used to prevent temporary file from filling the root filesystem.

/var: Log files are stored here. This is similar to the situation with /tmp, where user files can fill any available space if something goes wrong or if the files are not cleaned periodically.

/usr: This directory hold a hierarchy of directories containing user commands, source code, and documentation. It is often quite large, making it a good candidate for its own partition. Because much of the information stored under /usr is static, some users prefer that it be mounted as read-only, making it impossible to corrupt.

In addition to the preceding six partitions listed, a swap partition is also necessary for a Linux system to enable virtual memory.

Tuesday, December 7, 2010

Access specifier

In Object Oriented Programming there are three types of access specifier is available. They are:

1.private
2.public
3.protected

syntax:
access_specifer:
member declarations;

private:
private members are private to class,which mean it allows the instance member to access within the class, access beyond that class scope makes error.
private data members are accessed through class public member functions.
In C++ private is default to class it means if we didn't specify any specifier its private to that class

syntax:
private:
member declaration;

Example:
private:
int reg_no;

public:
public members are public to a program/class, which means its like global variable of a program/class, we can access anywhere in the program/class. In java public is default to class it means if we didn't specify any specifier its public to that program/class.

syntax:
public:
member declaration;

Example:
public:
reg_no;

protected:
protected is same as private, we cant able to access the protected variable beyond a class scope. But, when we inherit the protected members of a class, we can able to access those protected member as private to that derived class.

syntax:
protected:
member declartion;

Example:
protected:
char address[40];

Accessing class members

Accessing class members:
class members are accessed within the class.
class members are accessed through class member function.
instance of a class is needed to access class public/private members, outside of its class scope.


Note: private members of a class cannot able to access outside of the class scope. To know more refer access specifiers.


syntax for accessing class members through object:


a dot operator(.) is used to access the class members through instance of a class.

object_name.member_of_a_class;


Example:
S.name='Raja';
here 'S' is object for the class Student and 'name' is instance variable of that class.

Here is a small example to demonstrate accessing class members.

class Student
{
char name[30];
void get_details;
void display_details;
private:
int reg_no;
protected:
char address[40];
}
class Student_details extends Student //inheritance
{
 address="Saveetha Engg College, Chennai.";//derived can access the protected member of a class.*/
reg_no=1042;/*generates error, because scope of the private member is within the class. Not outside of a class or derived class*/
}
class Main
{
public static void main(String args[])
{
Student S=new Student();
S.get_detials();
S.display_details();
S.name="Ragu";
S.reg_no;/*this line generates error. Because we are allowed to access protected member only inside the scope and derived class*/
S.address;/*this line also generates error. Because we are allowed to access protected member only inside the scope*/
}
}

Introduction to Object

Object:

object is the 'instance of the class'.
object contains all the details of the class.
object allocates memory to the class non-static variables.
object has physical reality,i.e., an object occupies physical space in memory.

syntax:
1. class_name object_name;

2. class_name=new class_name();//class_name() is made a call to its class default constructor.

In C++ 1.will create instance for a class, 2. allocates memory statically i.e., at run time in. In JAVA 1. will be reference and the 2. will be instance for a class.

Example:
Student S=new Student();

Introduction to Class

Class:
class is a real world entity.
class contains its own data members and function members.
class is a data type, we can create a variable of a class type.
class is a instance of variables.
class is a logical construct.

syntax:
class class_name
{
access specifier:
datamembers declaratrions;
function member declaarations;
class body;
} object list;

The above syntax is for c++

for java the syntax is as follows:

syntax:
class class_name
{
access specifier:
datamembers declaratrions;
function member declaarations;
class body;
}

the syntax diffecence between c++ and java is semicolon(;) is not expected at the end of the class, while in c++ it is expected. Because in c++ the structure of the class is similar to that of 'Structres'. Here 'class' is a keyword.

Example in java:
class Student
{
char name[30];
int reg_no;
void get_details;
void display_details;
}