2 votes 2 votes Void fun(){ int i=0; Printf("%d", i); Static in j=12; // this is error to declare here right????? J=j+1; } Programming in C programming-in-c + – akankshadewangan24 asked Jan 18, 2018 akankshadewangan24 507 views answer comment Share Follow See all 7 Comments See all 7 7 Comments reply joshi_nitish commented Jan 18, 2018 reply Follow Share no, there will be no error, because when you write static int j=12; you are both declaring as well as defining a variable j. if you would have only written static int j; then it would give semantic error because static int j; will only declare j but does not allocate memory for it. 0 votes 0 votes Anu007 commented Jan 18, 2018 reply Follow Share Nitish I am not getting what you want to say here, yes program work fine here. #include<stdio.h> void main(){ int i=0; printf("%d", i); static int j= 10; // this is error to declare here right????? j=j+1; } this is also fine : #include<stdio.h> void main(){ int i=0; printf("%d", i); static int j; // this is error to declare here right????? j=j+1; } this is also fine : #include<stdio.h> void main(){ int i=0; static int j; // this is error to declare here right????? j=j+1; printf("%d", j); } 0 votes 0 votes joshi_nitish commented Jan 18, 2018 reply Follow Share i am highly sorry, i misread the word static as extern, and then that word got stucked in my mind, and i answered it assuming that in the qsn it has given extern 0 votes 0 votes Anu007 commented Jan 18, 2018 reply Follow Share its ok but here i dont under stand the logic. #include<stdio.h> void main(){ int i=0; printf("%d", j); static int j; // this is error to declare here right????? j=j+1; } why it gives error since static get memory at compile time and by default contain 0 also ans should be 0 but it gives error. 0 votes 0 votes joshi_nitish commented Jan 18, 2018 reply Follow Share because, every variable should be declared before its usage, else it will give semantic error. print(j) is used before declaration of static int j; 2 votes 2 votes Anu007 commented Jan 18, 2018 reply Follow Share static int j; memory allocated at compile time isnt? compiler know about variable at compile time isnt? if it was int j ; then i am ok that it will be semantic error. 1 votes 1 votes akankshadewangan24 commented Jan 18, 2018 reply Follow Share So this will give compile time error right?????? 0 votes 0 votes Please log in or register to add a comment.