Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Weird output for character pointers

$
0
0
For this one problem on my homework assignment, it says to initialize the pointer ptr and make it point to the first element of the array. Here is what I have written:

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
using namespace std;

int_tmain(int argc, _TCHAR* argv[])
{
char array[6] = {'a','b','F','H','X','Y'};
char *ptr;
ptr = &array[0];

cout << ptr << endl;

system("PAUSE");
return 0;
}



When I run this, the output gives me "abFHXY" and then some lines and symbols. Is this correct? If not then what am I doing wrong?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>