

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Redeclaration of global variable in C
Here we will see what is re-declaration of global variables in C. Does C supports this or not. Let us see the following code to get the idea about it.
Example
#include <stdio.h> int main(){ int a; int a = 50; printf("a is : %d\n", a); }
Output
[Error] redeclaration of 'a' with no linkage
So we can see that we cannot re-declare local variables. Now let us see what will be the output for global variables.
Example
#include <stdio.h> int a; int a = 50; int main(){ printf("a is : %d\n", a); }
Output
a is : 50
So global variables are not creating any error in this case. Now let us see if the first declaration is holding one value, then it can be re-declared or not?
Example
#include <stdio.h> int a = 10; int a = 50; int main(){ printf("a is : %d\n", a); }
Output
[Error] redefinition of 'a'
So we can see that we can only re-declare global variables, when they are not initialized.
- Related Questions & Answers
- C Program to Redeclaration of global variable
- How to declare a global variable in C++
- Global Special Variable Types in Perl
- Difference Between Local and Global Variable
- Difference between static, auto, global and local variable in C++
- How to declare a global variable in PHP?
- Create global variable in jQuery outside document.ready function?
- How to declare a global variable in Python?
- How to set a global variable in Postman?
- How to create a Global Variable in Postman?
- How to use Global Variable in Postman Request?
- How to define global variable in a JavaScript function?
- How to create and use Global Variable in swift
- Get global variable dynamically by name string in JavaScript?
- How to use a global variable in a Python function?
Advertisements