Initializing Variables And The Assignment Operator - C Data Type

C examples for Data Type:Introduction

Introduction

The following code declares two variables: one integer and one character data type.

After creating the two variables, the code initializes them to a particular value.

\0 is known as the NULL character.

Demo Code

#include <stdio.h> 
int main() //  www.  j a  v a2 s.co  m
{ 
    /* Declare variables */ 
    int x; 
    char firstInitial; 
    
    /* Initialize variables */ 
    
    x = 0; 
    firstInitial = '\0'; 

    printf("data Initializing."); 
} 

Result

You can also initialize your variables while declaring them, as shown next.

int x = 0; 
char firstInitial = '\0'; 

The preceding code accomplishes the same tasks in two lines as what the following code accomplishes in four.

int x; 
char firstInitial;  
x = 0; 
firstInitial = '\0';

Related Tutorials