See a problem in else if statement

Dangling else problem

Image
Hello, This problem comes when we use else if statement and do some mistake more describe is given below......... Dangling else problem: One of the major problem with nested if is dangling else problem. The problem arises when both outer if statement inner if statement might pair with common else statement. Thus the compiler is not able to judge to pair the else with which statement. The solution to this problem is given by the compiler that it pairs else with the recent if thus sometimes giving wrong result.                                           Hence the programmer should put early bracket wherever required. This post is may very short because my only aim was to describe this problem. Thank you, Keep supporting............. 

Storage Class in C Part 1

Hello guys today in this post we will discus about storage class.

Storage class:

Every identifiers not only has data type but also has a storage class the storage class the storage class of an identifiers determine the following character- 
  • scope of an identifiers
  • Storage of an identifiers
  • Storage location of an identifiers 
  • Lifetime of an identifiers
  • Linkage of an identifiers
  • Initial value of an identifiers
The storage class of an identifiers can be specified will the help of storage class specified 
following are storage class specifiers-

  1. auto
  2. static
  3. typedef
  4. register
  5. extern
It most one storage  class specifier can be specified in a declaration statement.

Auto:

  • Keyword used in auto.
  • By default an identifiers declared with in a block has auto storage class.
  • The auto identifiers is stored in main memory.
  • The lifetime of automatic storage class is local i.e. the identifiers will come into existence from the point if its declaration and remaining into existence till the control goes out of the block.
  • Auto identifiers are not initialized by default i.e. they have garbage value.
  •  auto identifiers can not be declared globally.
  • They have no linkage.
Ex.
#include<stdio.h>
main()
{
auto int a=10;
printf("The value of a is %d \n",a);
{
int a=20;
printf("The value of a inside block is %d ",a);
}
printf("The value of a outside block  %d \n",a);
}

Output:
The value of a is 10
The value of a inside block is 20
The value of a outside block is 10

register:

  • Keyword used is register.
  • Register storage class specified that the declared object will have local scoe
  • It cannot be used in the declaration mode in the global scope.
  • It is not initialized and needs to be initialized in the program.
  • The address of register identifiers cannot be accessed hence applying will give compile time error.
  • The register identifiers is stored in CPU register instead of main memory hence can be accessed faster. If CPU register are not available then It is stored in main memory and treated as auto storage class.
  • Register storage class is commonly used for loop counters to improve the performance of program.

Static:

  • keyword used is static.
  • The lifestyle of static storage class can be declared with global and local scope.
  • The variable of static storage class are implicitly initialized and not implicitly initialized value is 0 if int type 0.0 if float type and  ' \0 ' if class type.
  • It is stored in main memory.
  • Static storage class can be declared with global and local scope.
  • Static storage class variable when declared globally have external linkage and if declared locally have internal linkage.
  • static variable can not be used as parameter.
Ex.
#include<stdio.h>
main()
{
int a=0;
for (i=1;i<=5;i++)
{
for (a);a=a+1;
}
}
void fun (int b)
{
static int t=20;
printf("The value of b=%d &t=%d ",b,t);
printf("The value of t=%d after inc."++i);
}


KEEP SUPPORTING..............


Comments

Popular posts from this blog

Libraray Fine Hackerrank solution in C || Balanced Brackets Hackerrank solution in C

Permutations of Strings hackerrank solution in C || Permutations of Strings

Introduction to C part 2