Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6770645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:20:13+00:00 2026-05-26T15:20:13+00:00

I was confused with usage of %c and %s in the following C program:

  • 0

I was confused with usage of %c and %s in the following C program:

#include <stdio.h>
    
void main()
{
    char name[] = "siva";
    printf("%s\n", name);
    printf("%c\n", *name);
}

Output:

siva
s

Why we need to use pointer to display a character %c, and pointer is not needed for a string

I am getting error when I run

printf("%c\n", name);

I got this error:

str.c: In function ‘main’:
str.c:9:2: warning: format ‘%c’ expects type ‘int’, but argument 2 has type ‘char *’
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:20:13+00:00Added an answer on May 26, 2026 at 3:20 pm

    If you try this:

    #include<stdio.h>
    
    void main()
    {
     char name[]="siva";
     printf("name = %p\n", name);
     printf("&name[0] = %p\n", &name[0]);
     printf("name printed as %%s is %s\n",name);
     printf("*name = %c\n",*name);
     printf("name[0] = %c\n", name[0]);
    }
    

    Output is:

    name = 0xbff5391b  
    &name[0] = 0xbff5391b
    name printed as %s is siva
    *name = s
    name[0] = s
    

    So ‘name’ is actually a pointer to the array of characters in memory. If you try reading the first four bytes at 0xbff5391b, you will see ‘s’, ‘i’, ‘v’ and ‘a’

    Location     Data
    =========   ======
    
    0xbff5391b    0x73  's'  ---> name[0]
    0xbff5391c    0x69  'i'  ---> name[1]
    0xbff5391d    0x76  'v'  ---> name[2]
    0xbff5391e    0x61  'a'  ---> name[3]
    0xbff5391f    0x00  '\0' ---> This is the NULL termination of the string
    

    To print a character you need to pass the value of the character to printf. The value can be referenced as name[0] or *name (since for an array name = &name[0]).

    To print a string you need to pass a pointer to the string to printf (in this case name or &name[0]).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am confused with the otherwise and as long as usage in the following
Concerning the following usage, i'm confused how --i evaluates to true and what determines
Update: I probably confused memory usage issues with the UI sharing same thread as
I am bit confused in the usage of Static class, Private constructor and abstract
I am a little confused about the usage of cells and arrays in MATLAB
I am confused between NSString and NSMutable string usage. Suppose I have instance variables
Really confused why the QR output using RcppArmadillo is different than QR output from
I got confused understanding the usage of the volatile keyword in Java. I have
I'm a bit confused about the usage of Abstract classes in C#. In C++,
I'm confused with the use of the following methods of NSString initWithData:encoding: Returns an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.