#include<iostream>
void main()
{
char *p[3]={"Hi","to all"};
for(int i=0;i<=2;i++)
cout<<p[i]<<endl;
}
array of pointer
Page 1 of 19 Replies - 164 Views - Last Post: 05 October 2012 - 03:45 AM
#1
array of pointer
Posted 05 October 2012 - 02:29 AM
The code is giving runtime error, explain please???
Replies To: array of pointer
#2
Re: array of pointer
Posted 05 October 2012 - 02:37 AM
You declared an array containing three char*s, but only supplied two strings in your list. This means that the third one will be a null pointer. So when you're doing cout << p[2] << endl;, you're dereferencing a null pointer and thus invoking undefined behavior.
PS: The standard return type for main is int, not void.
PS: The standard return type for main is int, not void.
This post has been edited by sepp2k: 05 October 2012 - 02:38 AM
#4
Re: array of pointer
Posted 05 October 2012 - 02:51 AM
Initializing error here, why???
int *p[3]={1,2,3};
int *p[3]={1,2,3};
#5
Re: array of pointer
Posted 05 October 2012 - 02:52 AM
Are you just asking questions off of a test or quiz page?
What is p an array of, and what are you trying to use to initialize it?
What is p an array of, and what are you trying to use to initialize it?
#6
Re: array of pointer
Posted 05 October 2012 - 02:55 AM
I am just practicing array of pointers and could not understand the reason???
#7
Re: array of pointer
Posted 05 October 2012 - 03:02 AM
Answer this:
Quote
What is p an array of, and what are you trying to use to initialize it?
#8
Re: array of pointer
Posted 05 October 2012 - 03:12 AM
P is array of pointers and I am initializing to integers!!!
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|