C Programs | IT Developer
IT Developer

C Programs



Share with a Friend

C Program: Print Name, Age, and Address

A C program can be written to print your name, age, and address. This involves using the printf() function from the stdio.h header file to display the information on the console.

C Program: Print Name, Age, and Address

C

#include <stdio.h> // Include the standard input/output library

 

int main() {

    // Declare variables to store name, age, and address

    char name[] = "Anand Rao"; // Character array to store the name

    int age = 30;              // Integer variable to store the age

    char address[] = "123 Main Street, Bangalore, India"; // Character array for address

 

    // Print the information using printf()

    printf("Name: %s\n", name);    // %s is the format specifier for strings

    printf("Age: %d\n", age);      // %d is the format specifier for integers

    printf("Address: %s\n", address); // %s is the format specifier for strings

 

    return 0; // Indicate successful program execution

}

Output

 
OUTPUT 1 :
Name: Anand Rao
Age: 30
Address: 123 Main Street, Bangalore, India

Explanation:

  • #include <stdio.h>: This line includes the standard input/output library, which provides functions like printf()for displaying output.
  • int main() { ... }: This is the main function where program execution begins.
  • Variable Declaration:
    • char name[] = "Your Name";: Declares a character array nameand initializes it with the string "Your Name".
    • int age = 30;: Declares an integer variable ageand initializes it with the value 30.
    • char address[] = "123 Main Street, City, Country";: Declares a character array addressand initializes it with the specified address string.
  • printf()statements: These lines use the printf() function to display the information:
    • printf("Name: %s\n", name);: Prints the label "Name: " followed by the value of the name%s is a format specifier indicating that a string will be printed. \n creates a new line.
    • printf("Age: %d\n", age);: Prints "Age: " followed by the value of the age%d is a format specifier for integers.
    • printf("Address: %s\n", address);: Prints "Address: " followed by the value of the address
  • return 0;: This statement indicates that the program executed successfully.