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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:00:10+00:00 2026-05-12T10:00:10+00:00

I am new to C and reviewing some source code. But I am not

  • 0

I am new to C and reviewing some source code. But I am not sure what is happening with this code snippet.

I really don’t think it is doing anything, as in the debugging the output seems to be the same for tempstr.

This is what I think, correct if I am wrong.
*(tempstr + strlen(line)) is adding the length of line to tempstr and dereferencing and assigning the 0x0 converted to a char?

char line[128], tempstr[128]

strcpy(line, "AUTO_ANSWER_CALL = 1");
strcpy(tempstr,line);
*(tempstr + strlen(line)) = (char) 0x0; // Confusing part
  • 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-12T10:00:10+00:00Added an answer on May 12, 2026 at 10:00 am

    This is a pointer value:

    tempstr
    

    This is another pointer value (which points to 5 elements beyond the tempstr pointer value):

    tempstr + 5
    

    This is an integer:

    strlen(line)
    

    Therefore, this is a pointer value (which points to strlen(line) elements beyond the tempstr pointer value):

    tempstr + strlen(line)
    

    And this is dereferencing that pointer:

    *(tempstr + strlen(line))
    

    This is what I think, correct if I am wrong. *(tempstr + strlen(line)) is adding the length of line to tempstr and dereferencing and assigning the 0x0 converted to a char?

    It’s ensuring that the character at index 20 of tempstr, immediately beyond the “AUTO_ANSWER_CALL = 1” characters, is null: i.e. it’s ensuring that the string is null-terminated.

    That string already is null-terminated, by the way (so that last statement is redundent): because strcpy copies the string including the implicit null-termination character.


    Isn’t easier just to do the following tempstr[sizeof(tempstr)-1] = ‘\0’; this is much easier to understand.

    These aren’t the same thing: strlen(line) equals 20, but sizeof(tempstr) equals 128.


    would this work: tempstr[strlen(tempstr)] = ‘\0’

    That’s exactly the same things as:

    *(tempstr + strlen(tempstr)) = '\0'
    

    Just a different way of writing it.

    However, if tempstr is NOT a null terminated string, the length would be 128 as well.

    If tempstr is NOT a null terminated string then strlen(tempstr) is undefined (‘undefined’ means that it’s meaningless and dangerous, a bug, and shouldn’t be used): the strlen function isn’t valid except when it’s used on a string that’s already null-terminated.

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

Sidebar

Related Questions

Was recently reviewing some Java Swing code and saw this: byte[] fooReference; String getFoo()
Hey guys, I'm reviewing some questions but I can't really figure it out, i
I have been reviewing some code that looks like this: class A; // defined
I'm reviewing some new code. The program has a try and a finally block
A new collaborator of mine who was reviewing some code I'd written told me
I am new at DirectShow, so some parts of this library i don't understand
New programmer here, I am trying to understand and break down this code below
I'm reviewing some code in VB.net, and in a validation object they have written
I am reviewing some code at work and came across an inconsistency in how
Some I'm reviewing some code within my team's code base, where we traverse over

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.