bugmenot 25 Posting Whiz in Training

Is there any programming reason why I always see function definitions with arguments like this:

char getchar(char *arr){

Instead of this?:

char getchar(char arr[]){

These are identical. It is a pointer in both cases. So I guess it may be more clear to write it as a pointer. The second case might cause beginners to think that you are passing an entire array by value or something like that.

Also this code:

const char anonymous[ ] = "123";
char *arr = anonymous;

Didn't work for me, it gives a " invalid conversion from `const char*' to `char*'" compile error.

Yes. Either "arr" needs be changed to be declared as "const char *", or "anonymous" needs be changed to be declared as "char []".

Would it be correct to say that char *arr = "123"; is like this to the compiler:

char anonymous[ ] = "123";      
char *arr = anonymous;

Without the constant declaration?

No. There are two special syntaxes here. But they are very different. The line 'char *arr = "123" ' makes a string literal (which is stored specially in some special part of memory by the compiler, and exists for the entire duration of the program) and gives the location of that to the pointer. The second code example creates an array which is a local variable of the current function, and initializes it. As a local variable, it only exists until the function returns, so it would be bad to return a pointer to it or refer it …

bugmenot 25 Posting Whiz in Training

This seemed inefficient to me, so I looked around for another way. Here is a simpler way to do it, using the sqlite3.Cursor.description attribute.

from sqlite3 import dbapi2 as sqlite
cur.execute("SELECT * FROM SomeTable")
col_name_list = [tuple[0] for tuple in cur.description]

cur.description returns a tuple of information about each table. The entire tuple is : (name, type_code, display_size, internal_size, precision, scale, null_ok)

bugmenot 25 Posting Whiz in Training
sphere::sphere()        //default constructor
{
	int Radius=0;
}

wow.

what did you expect that code to do?

Ancient Dragon commented: I missed that :) +28
bugmenot 25 Posting Whiz in Training

if you want a dynamic array, which has a finite size that grows and shrinks as you add or remove elements, take a look at std::vector

Suraine commented: Thanks for the suggestion :) +1
bugmenot 25 Posting Whiz in Training

So is this the equivalent of the following in C++?

yes. (except that in Java the first object is garbage-collected and in C++ it isn't)

bugmenot 25 Posting Whiz in Training
attribute[] attr=new attribute[no_of_attribute];

attr has no_of_attribute arguments

for(int i=0;i<no_of_entity;i++){

i goes from 0 to no_of_entity

for(int j=0;j<no_of_attribute;j++){

j goes from 0 to no_of_attribute

j is never used

System.out.println("The name of the attribute="+this.attr[i].name);

you access attr

but i might be bigger than the size of attr, which is no_of_attribute
because no_of_entity might be bigger than no_of_attribute

PoovenM commented: Good one on the debug! +2