Logo - ProgrammingHead

Write a Program to Display your Name in C [Updated 2025]

To write a Program to Print your Name in C, we have the printf() function in C Language.
You just have to write your Name inside the printf() function and you will be able to Print or Display your Name.

Write a Program to Display your Name in C [Updated 2025]

myname.c

#include<stdio.h>
void main(){
  printf("Name: John");
}

Results

Name: John

Steps to Print Name in C:

1) First Open Your C Compiler
(For Example Code::Blocks)
2) Create a New File And Save that File With a name.
(for example myname.c)
3) Write the code As shown Above.
4) Save and Run your C Program.

C Code explanation in detail

Use of #include:

By using #include, we are including all the Standard Input-Output Header files.
So #include going to include
std standard Input Output .h Header file.

Use of void main()

Here main() is our Main function, where we are using void because this function is not going to return any value.
We can also use int main() or char main() depending upon the type of value we are going to return.

Use of printf()

By using printf(), we are Printing our Name or a String.
Where printf() function will take the value as an Input and Display it as an Output.

Related Topics: Write a Program to Display your Name in C [Updated 2025]

Click on Titles below to reveal the Data

Write a C Program to input name and Display

In order to Input a Name and Display it in C, we need to use two very Important C Functions,
printf() and scanf().
Where by using printf() function we will print things like "Write your name", to tell our users to Enter their name.
Then by using scanf() function we will store their entered name inside a C Variable myname.
By using scanf("%s", &myname), we are telling our compiler that we are expecting a String "%s" value and we want to store that String value inside our variable "&myname".
At the end we will Display/Print the Name using the printf() funtion. Here we are using "%s" as our String Placeholder and printf() function will print our myname variable's value there.

name.c

#include<stdio.h>  
void main()  
{
    char myname[20];
    printf("Enter your Name: ");
    scanf("%s", &myname);
    printf("Your name is: %s", myname);
}

Results

Enter your Name: John
Your name is: John

Writing a C program to Print the Name and Address

To print your Name and Address we can use printf() Function.
Just write your name inside The C Print Function [ printf("Name and Address"); ] and you are DONE.

nameaddress.c

#include<stdio.h>  
void main()
{
  printf("My Name is John");
  printf("\nMy Address is : 21 Jump Street NY");    
}

Results

My Name is John
My Address is : 21 Jump Street NY

Writing a program to print your name at the center of the screen

To Print your name at the center of the screen. We have to use C Languageā€˜s gotoxy() function.
Where we need to provide X and Y digits to Perfectly align our Name at the Center of the Screen.

center.c (Only works with TurboC++)

#include<stdio.h>  
void main()
{
  gotoxy(40,13);  
  printf("Rosie");  
  getch();
}

center.c (Works with codeBlock)

#include <stdio.h>
#include <windows.h>
void main()
{
    COORD c;
    c.X = 40;
    c.Y = 16;
 
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
 
    printf("John");
    getch();
}

Write a C Program to Print Names using Array

If you have Multiple Names Stored inside an Array, then you can Loop through it and Print every name One-By-One.

array.c

#include <stdio.h>
void main()
{
    char mynames[3][20] = {"John", "Rick", "Emily"};
    int arrayLength = sizeof(mynames)/sizeof(mynames[0]);
    for(int i=0; i<arrayLength; i++){
        printf("
%s", mynames[i]);
    }
}

Results

John
Rick
Emily

In the Example above, we are using char mynames[3][20] to create an Array in C.
Where are specifying the Array and Character Length. Where [3][20] means that our Array will include 3 Values with a Max 20 Character Length.

Writing a C Program to Display Name and Age

To print Name and Age we have to deal with Characters and Integer values. Where for storing Character Values we have CHAR data type and for integers with have INT data type. And for address/format specifier we have %s for String and %d for Integers.

nameandage.c

#include <stdio.h>
int main()
{
    char name[20] = "John";
    int age = 25;
    printf("\nYour name is = %s", name);
    printf("\nYou are %d Years OLD", age);
}

Results

Your name is = John
You are 18 Years OLD

nameandage.c [Get User Inputs]

#include<stdio.h>
int main()
{
    char name[20];
    int age;
    printf("Enter your Name\n");
    scanf("%s", &name);
    printf("\nEnter your Age\n");
    scanf("%d", &age);
    printf("\nYour name is = %s", name);
    printf("\nYou are %d Years OLD", age);
}

Results

Enter your Name:
John
Enter your Age:
18

Your name is = John
You are 18 Years OLD