Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Difference of char * and int *

Difference of char * and int *

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformance
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sacoskun
    wrote on last edited by
    #1

    Hi, I would like to ask that; #include "stdafx.h" #include int _tmain() { int myInts[3] = {0,1,2}; char * myName = "sarp"; std::cout << myName << std::endl; std::cout << myInts << std::endl; return 0; } Why it prints out sarp in first output and memory location in second output? I was waiting for memory location of s in the first one. Also, what is the difference between; char * myName = "sarp"; char myName[] = "sarp"; Thanks, Sarp - When in doubt, push a pawn! -

    D M N 3 Replies Last reply
    0
    • S sacoskun

      Hi, I would like to ask that; #include "stdafx.h" #include int _tmain() { int myInts[3] = {0,1,2}; char * myName = "sarp"; std::cout << myName << std::endl; std::cout << myInts << std::endl; return 0; } Why it prints out sarp in first output and memory location in second output? I was waiting for memory location of s in the first one. Also, what is the difference between; char * myName = "sarp"; char myName[] = "sarp"; Thanks, Sarp - When in doubt, push a pawn! -

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      cout must have an overloaded method to output char*, and nothing to output int* ( except for the adress ).


      Maximilien Lincourt Your Head A Splode - Strong Bad

      1 Reply Last reply
      0
      • S sacoskun

        Hi, I would like to ask that; #include "stdafx.h" #include int _tmain() { int myInts[3] = {0,1,2}; char * myName = "sarp"; std::cout << myName << std::endl; std::cout << myInts << std::endl; return 0; } Why it prints out sarp in first output and memory location in second output? I was waiting for memory location of s in the first one. Also, what is the difference between; char * myName = "sarp"; char myName[] = "sarp"; Thanks, Sarp - When in doubt, push a pawn! -

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        kromozom wrote: Why it prints out...memory location in second output? What would you expect it to print out? kromozom wrote: I was waiting for memory location of s in the first one. Then you should use cout << &myName << endl; instead.


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        1 Reply Last reply
        0
        • S sacoskun

          Hi, I would like to ask that; #include "stdafx.h" #include int _tmain() { int myInts[3] = {0,1,2}; char * myName = "sarp"; std::cout << myName << std::endl; std::cout << myInts << std::endl; return 0; } Why it prints out sarp in first output and memory location in second output? I was waiting for memory location of s in the first one. Also, what is the difference between; char * myName = "sarp"; char myName[] = "sarp"; Thanks, Sarp - When in doubt, push a pawn! -

          N Offline
          N Offline
          namaskaaram
          wrote on last edited by
          #4

          ;)well.....for thiz iz for ur info..... whenu declare the variable say.....

          char a[10];

          here the variable "a" is bacially like a pointer,it terminates only when it "sees" the "\O" thatz why u dont get the same answer..... if want just one letter to come do like thiz..... cout<<*(myname); if u want the second letter..... cout<<*(myname+1) and so on..... hope that helpz..... happy programmin..... cheerz..... :-D

          S 1 Reply Last reply
          0
          • N namaskaaram

            ;)well.....for thiz iz for ur info..... whenu declare the variable say.....

            char a[10];

            here the variable "a" is bacially like a pointer,it terminates only when it "sees" the "\O" thatz why u dont get the same answer..... if want just one letter to come do like thiz..... cout<<*(myname); if u want the second letter..... cout<<*(myname+1) and so on..... hope that helpz..... happy programmin..... cheerz..... :-D

            S Offline
            S Offline
            sacoskun
            wrote on last edited by
            #5

            Thanks all, I have cleared some of my confused knowledge... - When in doubt, push a pawn! -

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups