© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

13. Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

Ans:
It’s easier for a C compiler to generate good code for pointers than for subscripts.

Ex - 1:  Is the following code legal?
typedef struct a aType;
struct a
{
int x;
aType *b;
};
Ans:
Yes

Explanation:

The typename aType is known at the point of declaring the structure, because it is already typedefined.

Ex - 2 Is the following code legal?
void main()
{
typedef struct a aType;
aType someVariable;
struct a
{
int x;
      aType *b;
              };
}

Ans:
No

Explanation:

                        When the declaration, typedef struct a aType; is encountered body of struct a is not known. This is known as ‘incomplete types’.


SLogix Student Projects
bottom