1 What is reference pointer?2 Which C features are not in C++?3 Write a program of spiral matrix.4 Write a program of magic square.

  
Showing Answers 1 - 2 of 2 Answers

Dev

  • Apr 15th, 2006
 

Answers :

1.

A reference pointer is the less complex form of pointer. The most common use for this class of pointer is as a passing mechanism; for example, passing an integer by reference. Reference pointers have significantly better performance than full pointers, but are restrictive; you cannot create a linked list using a reference pointer because a reference pointer cannot have a NULL value, and the list cannot be terminated

A reference pointer has the following characteristics:

? It always points to valid storage; it can never have a NULL value.

? Its value does not change during a call; it always points to the same storage on return from the call as it did when the call was made.

? It does not support aliasing; it cannot point to a storage area that is pointed to by any other pointer used in a parameter of the same operation

2.

C++ is often considered as a superset of C, but this is not strictly true. Most C code can easily be made to compile correctly in C++, but there are a few differences that cause some valid C code to be invalid in C++, or to behave differently in C++.

Perhaps the most commonly encountered difference is that C allows implicit conversion from void* to other pointer types, but C++ does not. So, the following is valid C code:

int *i = malloc(sizeof(int) * 5);     /* Implicit conversion from void* to int* */

but to make it work in both C and C++ one would need to use an explicit cast:

int *i = (int *) malloc(sizeof(int) * 5);

Another common portability issue is that C++ defines many new keywords, such as this and class, that may be used as identifiers (e.g. variable names) in a C program.

3.

Of course, given any magic square, rotating it or reflecting it will produce another magic square.  Not counting these as distinct, it is known that there is only one normal magic square, and there are 880  normal magic squares.  The number of normal magic squares increases dramatically as the size of the square increases.  For instance, there are over 13 million normal magic squares!

  Was this answer useful?  Yes

lr

  • Jul 30th, 2006
 

its very good and useful to share

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions