Saturday, 24 August 2013

What is the difference between String and Character Array?

String  have static storage duration, While character array not, unless it is specified by using the static  keyword.
Moreover a string is a character array having properties: 
  • the sequence of character, generally call string, is  an array .This array contain all characters plus a NULL character.
  • we cant modify it.
  • two string having same value may share same memory .
DECLARATION: 
char a[ ] = "Kumar and Bucky”; Character Array 
char *s = “Calvin and Hobbes”;     String


Friday, 23 August 2013

What is difference between Call by value and Call by reference?

There are two different methods for passing a variable in function as a parameter:

1.Call by value:  we pass copy of actual variables in function as a parameter. Any changes on parameters inside the function will not effect the actual variable.

#include<stdio.h>
void main(){
    int a=5,b=10;
    change(a,b);
    printf("%d      %d",a,b); 
    
} 
void change(int a,int b){
    a=a+b;
    b=a-b;
   a=a-b;
}
Output: 5    10

2.Call by reference: we pass memory address of  actual variables in function as a parameter. Hence if we make any changes on parameters inside the function will effect the actual variable.

#include<stdio.h>
int main(){
    int a=5,b=10;
    change(&a,&b);
    printf("%d %d",a,b);
    return 0;
} 
void swap(int *a,int *b){
    int  *temp;
    *temp =*a;
    *a=*b;
    *b=*temp;
}

Output: 10 5

Top 5 different ways by which user can store online data for free

1.Sky Drive :is online free storage for storing data .It provides the      user to store data above 5+Gb for free.Sky Drive is now days         providing store of online data for free
             CLICK HERE TO GO TO SKY DRIVE


2. Google Drive is Online free storage for free up to 5 GB .User       can simply lo gin from   their g mail    account to access this free     online storage for free
                                                                                                                                                                                             

                               
        CLICK HERE TO GO TO G MAIL DRIVE



3.DROP BOX is another online free storage container where user can store free up to 2GB for free of    cost.User can Download Drop Box for free and can easily store data online for free .

        CLICK HERE FOR DROP BOX

4. YOU FILE LINK is also online free storage proving it's user to store data free up to 5GB.



              CLICK HERE FOR YOUFILELINK

5. SUGARSYNC is providing free online storage for free up to       5GB.  


               


Thursday, 22 August 2013

Arrays in c

An array is derived data type which can store similar type of data in sequence memory location. Data may be primitive type i.e  int, char, float, double…
C Programming
C Programming

Example of array declaration:

int a[5];
char a[5];
float a[5];
long double a[5];
char * a[5];
int (a[])();
double ** a[5];

Array is useful when:

(a) We have to store large number of data of similar type.:
void main(){
    int a=1;
    int b=2;
    int c=5;
    int d=7;
    int e=8;
    int f=0;
    int g=11;
    int h=5;
    int i=90;
    int avg;
    avg=(a+b+c+d+e+f+g+h+i)/9;
    printf("%d",avg);
   }
If we  use array then the same program will written as;
void main(){
    int a[ ]={1,2,5,7,8,0,11,5,50};
    int i,avg;
    for(int i=0;i<12;i++){
         avg=avg+a[i];
    }
printf("%d",avg/9);
}

Advantage of using array:

1. An array provides single name for many variables of same data type.
2. Array is used in data structure like. implementation of stack Queue, Tree etc.
C - Overview
C - Basic Syntax
C - Data Types
C - Variables
C - Constants
C - Storage Classes
C - Operators
C - Decision Making
C - Loops
C - Functions
C - Scope Rules
C - Arrays
C - Pointers
C - Strings
C - Structures
C - Unions
C - Bit Fields
C - Typedef
C - Input & Output
C - File I/O
C - Preprocessors
C - Header Files
C - Type Casting
C - Error Handling
C - Recursion
C - Variable Arguments
C - Memory Management
C - Command Line Arguments

How to print Hello with out using ;(semi-colon)?

This can be done using following ways:

1.#include<stdio.h>
void main(){
    if(printf("Hello world")){
    }
}



2.#include<stdio.h>
void main(){
    while(!printf("Hello world")){
    }
}



3.#include<stdio.h>
void main(){
    switch(printf("Hello world")){
    }
}

Monday, 19 August 2013

Difference between Declaring a variable , Defining a variable ,Internal static variable and External static variable

Declaring a variable

Declaring a variable means describing its type (data type) but not allocating any space for it.

Defining a variable:

Defining a variable means declaring it and also allocating space to hold the variable. and it may be initialize at the time it is defined.

1.Internal static variable

An internal static variable is declared inside a block with static storage class.An internal static variable has persistent storage,block scope and no linkage.

2.External static variable

 An external static variable is declared outside all the blocks in a file and  has permanent storage,file scope and internal linkage.

Sunday, 18 August 2013

Difference between Malloc and Calloc

1. calloc(...) allocates a block of memory for an array of elements  of a certain size. By default the block is initialized to Zero. The  total number of memory allocated will be (number_of_elements *  size).malloc(...) takes in only a single argument which is the  memory required in bytes. malloc(...) allocated bytes of memory      and not blocks of memory like calloc(...)
2. malloc(...) allocates memory blocks and returns a void pointer to the allocated space, and null if there is insufficient or no memory available. calloc(...) allocates an array in memory with elements initialized to 0 and returns a pointer to the allocated space. malloc(...) can be call by calloc(..) in order to use the C++ _set_new_mode function to set the new handler mode.

Difference between printf("%d") and printf("%d",x)


1. When we write printf("%d",x); the compiler will print the
value of x. But where there is nothing after %d so compiler will show  garbage value.

2. When we use %d the compiler internally uses it to access the
argument in the stack called argument stack. Compiler determines
the offset of the variable depending on the format specification
string. Now when we write printf("%d",x) then compiler first accesses the top most element in the argument stack of the printf which is %d and depending on the format string it calculated to offset to the actual data variable in the memory which is to be printed. Now when only %d will be present in the printf then compiler will calculate the correct offset (which will be the offset to access the integer variable) but as the actual data object is to be printed is not present at that memory location so it will print what ever will be the contents of that memory location.

3. Some compilers check the format string and will generate an error.