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

  • Home
  • SEARCH
  • 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 6169257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:49:40+00:00 2026-05-23T22:49:40+00:00

I am thinking of something like: #include <stdio.h> #include <conio.h> #include <stdlib.h> int main(void)

  • 0

I am thinking of something like:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main(void) {
    //test pointer to string
    char s[50];
    char *ptr=s;
    printf("\nEnter string (s): ");
    fgets(s, 50, stdin);
    printf("S: %s\nPTR: %s\n", s, *ptr);

    system("PAUSE");
    return 0;
}

Or should I use a for loop with *(s+i) and the format specifier %c?
Is that the only possible way to print a string through a pointer and a simple printf?

Update: The printf operates with the adress of the first element of the array so when I use *ptr I actually operate with the first element and not it’s adress. Thanks.

  • 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-23T22:49:41+00:00Added an answer on May 23, 2026 at 10:49 pm

    The "%s" format specifier for printf always expects a char* argument.

    Given:

    char s[] = "hello";
    char *p = "world";
    printf("%s, %s\n", s, p);
    

    it looks like you’re passing an array for the first %s and a pointer for the second, but in fact you’re (correctly) passing pointers for both.

    In C, any expression of array type is implicitly converted to a pointer to the array’s first element unless it’s in one of the following three contexts:

    • It’s an argument to the unary “&” (address-of) operator
    • It’s an argument to the unary “sizeof” operator
    • It’s a string literal in an initializer used to initialize an array object.

    (I think C++ has one or two other exceptions.)

    The implementation of printf() sees the "%s", assumes that the corresponding argument is a pointer to char, and uses that pointer to traverse the string and print it.

    Section 6 of the comp.lang.c FAQ has an excellent discussion of this.

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

Sidebar

Related Questions

I am thinking about something like this: public static <T extends Comparable<T>> T minOf(T...ts){
I'm thinking of something like Jython/Jango? Does this exist? Or does Jython allow you
I was thinking about making something like Linq for Lua, and I have a
What I am thinking of is something like the this keyword but at a
Are there any open-source libraries that all programmers should know about? I'm thinking something
How can I convert PDF files to HTML with Python? I was thinking something
I'm thinking of something smaller than a laptop that i can spend my hours
Is there a way to implement/use lambda functions in bash? I'm thinking of something
This is something that comes up so often I almost stopped thinking about it
Thinking about getting into .net technology project management I've had plenty of experience with

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.