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 6183647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:24:07+00:00 2026-05-24T01:24:07+00:00

Going through K&R I saw the following code snippet of a function, strcopy, which

  • 0

Going through K&R I saw the following code snippet of a function, strcopy, which copies a character array to another.

If t is the pointer to the first array, and s is the pointer to the array which t is copied to, the code is:

void strcopy(char *s, char *t){

     while(*s++=*t++)
             ;
}

I’m confused by the while loop. I undersatnd that inside the condition t is copied to s, but I don’t understand what condition is being tested here. When will *t++ be false (or zero)? Presumably, when the character string finishes. We can test whether the string is finished by checking if the character pointed at is '\0'. K&R says as much. But then the book rather blithely points out that this test isn’t necessary. So I’m wondering what is being tested here?

  • 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-24T01:24:09+00:00Added an answer on May 24, 2026 at 1:24 am

    *s++ = *t++ will evaluate to the value that was assigned. At the end of the string, *t will be '\0', and upon assignment the expression will evaluate to '\0' (which C interprets as false).

    I guess K&R are saying that an additional test is not necessary, since everything is handled in the while condition.

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

Sidebar

Related Questions

I was going through a legacy code and found the following snippet: MyClass::~MyClass() {
I'm new to programming & i found this code when i was going through
While going through university and from following the development of SO, I've heard a
I was going through some code and came across a scenario where my combobox
I was going through Getting Started (with PostSharp ) And when I saw PostSharp
I'm just starting programming and going through K&R to try and learn C. I've
All, I'm going through the Friedman & Felleisen book A Little Java, A Few
I'm going through the Beginning iPhone Development book & stuck in chapter 9. I've
I'm starting to learn C by reading K&R and going through some of the
I was going through an article today when it mentioned the following: We've found

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.