2,458 views

2 Answers

1 votes
1 votes
without declaration of variable p gives error. And in main() function you defined p variable 2 times.

#include <stdio.h>
 extern int p;
int main()
{  
       int p = 90;
       printf("%d ", p);
 
}

it gives output 90
0 votes
0 votes
Extern variables are initialized to zero by default and are globally accessible.

Extern variables must be defined exactly once, outside any function- this sets aside storage for it. And the function that wants to access the extern variable must declare it before using it.

Just put extern declaration outside the function and you get answer 0,90. 0 as extern is initialized to 0 by default and 90 after p is assigned value.

#include <stdio.h>

extern int p;
int main()
{
  int p;
  printf("%d ", p);
  {
       int p = 90;
       printf("%d ", p);
  }
}

Related questions

0 votes
0 votes
0 answers
1
I_am_winner asked Nov 13, 2018
177 views
1 votes
1 votes
0 answers
2
Parker12 asked Aug 10, 2017
500 views
1 votes
1 votes
2 answers
4
Nikhil Patil asked Feb 10, 2018
1,150 views
#include<stdio.h int main(void) { int p = 1; int q = 0; q = p++ + p++; printf("%d %d",p,q); return 0; }Output is Showing $3,3$ How ?