Posts

Showing posts from 2013

Change hostname in Solaris11

Solaris 11: Changing hostname Please perform following steps to change the host name: To change the hostname in Solaris 11, I followed this steps: 1 - To check the current environment properties: root@solaris:~# svccfg -s system/identity:node listprop config config                 application         config/enable_mapping boolean     true config/nodename       astring     solaris config/loopback       astring     solaris 2 - Set the new hostname root@solaris:~# svccfg -s system/identity:node setprop config/nodename="my-host-name" root@solaris:~# svccfg -s system/identity:node setprop config/loopback="my-host-name" 3- Refresh the properties: root@solaris:~# svccfg -s system/identity:node refresh 4 - Restart the service: root@solaris:~# svcadm restart system/identity:node 5 - verify that the changes took place: r oot@solaris:~# svccfg -s system/identity:node listprop config config                 application        config/enable_mapping boolean     true config/no

Storage Classes

Storage Classes -          A variable always have data type(int,float etc) but they also have a storage class or we can say a variable always need data type as well as storage class. -          As we had seen many examples before, but we did not use storage classes there, because variables also have default storage classes. So if we do not mention storage class, compiler will assume default. -          In computer we use two types of memory 1.      Internal Memory  2.      CPU Registers. -                     It is the variable’s storage class that determines in which of these two locations the value is stored. What is use of storage class? -          To know about life of variable -          To know about scope of variable -          To store variables in memory or registers -          To know initial value of variable, if we did not assign default value. Types of Storage classes:      There are 4 types of storage class 1.       Automatic Storage

External Storage Class

Image
  External Storage Class: ·        Values stores in memory only. ·        Default value of external storage value is zero. ·        Variable scope is global. ·        Life of variable is as long as the program’s execution doesn’t come to end ·        External variables declared outside function, So that function may use it. These variables are available to all functions. #include<stdio.h> void useFile(); /* this variable is external variable, its default value will be zero */ char* fileName="test.txt";     main( ) {        printf("File main function  - %s\n",fileName);              useFile(); } void useFile() {        printf("File useFile function  - %s\n\n",fileName); } In this program, we define an external variable (fileName) which is a char pointer. This variable is available in all function. We use filename in both function and we can see output in attached image. Example 2: #include<stdio.h> in

Static Storage Class

Image
  Static Storage class: ·        Variables stored in memory. ·        Default value of static variables is zero. ·        Scope of variables is local to block in which it is defined ·        Life of variables is till end of program. Its value initialized only one time and exists till complete execution. ·        auto and static both variables are local to block in which they defined, Difference only is that static variables don’t disappear when function is no longer alive. It remains in memory, so when control comes back to function , static values will be having same value as before. ·        As values of static variables kept in memory when variables are not active, So its wastage of memory. So we should use static variables only when you really need. Example: #include<stdio.h> void test();    // Function Prototype main( ) {       test();       test();       test(); } void test() {    static int i=1;   // Static variable    i=i+1;    printf("Function c

Register Variable Class

    Register Variable class ·        It stores variables in Register memory ·        Default value of register variables is garbage value. ·        Scope of register variables is also local to block. ·        Life of variables is also remains till control remains in block. ·        Values stored in register access more faster than values stored in memory ·        So if a variable is used at many places in program, it’s better to declare its storage class as register. So it will increase the performance of program. ·        CPU registers are limited. So during execution of program, value may be stored in register , because register may be busy doing another CPU tasks. At that time those variables will also works as auto variables.   ·        Keyword - register main() {       register int i;                    printf(“%d”,i); }

Automatic storage class

Image
Automatic Storage Class: ·        It stores variable in memory ·        Initial value of automatic class variables is garbage values. ·        Variable scope is local to block in which it is defined. ·        Life of variable will be only till control remains in block. ·        Keyword - auto Example:                   This example shows how to define a auto variable.           #include<stdio.h>      main( )      {           auto int i, j ;           printf ( "\n%d %d\n", i, j ) ; } In this example, we did not initialize I and j variable, so it displays garbage values after execution.    Example 2 : this example will illustrate scope of auto variable. #include<stdio.h> main( ) {           auto int test=100;           {                     auto int test=200;                     {                               auto int test=300;                              printf("%d   ",test);                      }            

Array

Image
Array : Difference between Array and Structure:                               Array                               Structure 1.       In array memory is static. We define the memory on declaration of array. 1.       In structure, memory is dynamic. 2.       It uses subscript to access elements. 2.       It uses Dot operator to access elements. 3.       Array is a base pointer and it points to base location 3.       Structure is not a pointer type. 4.       Array is collection of homogenous data. 4.       Structure is collection of heterogenous data. 5.       Array is derived data type. 5.       Structure is user defined data type. ·         In C languages, user can design a set of similar data types. When we need to store more than 1 value of similar data type, we use Array. ·         In c language, a simple variable can store only one value at a time. If we change the value, then pr