- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implicit initialization of variables with 0 or 1 in C
We know that we need to declare variables before using it in our code. However, we variables can be assigned with 0 or 1 without declaration. In the following example we can see this.
Example
#include <stdio.h> #include <stdlib.h> x, y, array[3]; // implicit initialization of some variables int main(i) { //The argument i will hold 1 int index; printf("x = %d, y = %d
", x, y); for(index = 0; index < 3; index++) printf("Array[%d] = %d
", i, array[i]); printf("The value of i : %d", i); }
Output
x = 0, y = 0 Array[0] = 0 Array[1] = 0 Array[2] = 0 The value of i : 1
Sometimes, if some array is initialized with few values, then rest of the values will hold 0.
#include <stdio.h> #include <stdlib.h> int main() { //The argument i will hold 1 int index; int array[10] = {1, 2, 3, 4, 5, 6}; for(index = 0; index < 10; index++) printf("Array[%d] = %d
", index, array[index]); }
Output
Array[0] = 1 Array[1] = 2 Array[2] = 3 Array[3] = 4 Array[4] = 5 Array[5] = 6 Array[6] = 0 Array[7] = 0 Array[8] = 0 Array[9] = 0
- Related Articles
- Initialization of static variables in C
- Initialization of global and static variables in C
- C++ static member variables and their initialization
- Can we declare final variables without initialization in java?
- What do you mean by a dynamic initialization of variables?
- Maximum length subarray with difference between adjacent elements as either 0 or 1 in C++
- Maximum length subsequence with difference between adjacent elements as either 0 or 1 in C++
- Set conditions for columns with values 0 or 1 in MySQL
- Initialization of a normal array with one default value in C++
- Which contains more heat, 1 kg of ice of 0° C or 1 kg of water at 0° C? Give reason for your answer.
- Collection Initialization in C#
- Variable initialization in C++
- Uniform Initialization in C++
- Zero Initialization in C++
- Which contains more heat, 1 kg of ice at 0° C or 1 kg of water at 0° C? Give reason for your answer.

Advertisements