GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 429 of 438    Print  
What will be difference b/w 5th and 6th statements?
1. #define MAX 100
2. main()
3. {
4. int max=100;
5. int a[MAX];
6. int b[max];
7. }



  
Total Answers and Comments: 3 Last Update: September 19, 2008     Asked by: Pramoda.M.A 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: vinayps03
 

Size of an array can't be dynamically resized at runtime (one of the reasons y v use data structures!)
5th line: size of a[MAX] is constant (100) --> so no probs here.
6th line: Compilation error..
c:Code(6) : error C2057: expected constant expression

c:Code(6) : error C2466: cannot allocate an array of constant size 0

c:Code(6) : error C2133: 'b' : unknown size



Above answer was rated as good by the following members:
sourabh_t
August 06, 2008 16:13:59   #1  
vinayps03 Member Since: August 2008   Contribution: 1    

RE: What will be difference b/w 5th and 6th statements?

Size of an array can't be dynamically resized at runtime (one of the reasons y v use data structures!)
5th line: size of a[MAX] is constant (100) --> so no probs here.
6th line: Compilation error..
c:Code(6) : error C2057: expected constant expression

c:Code(6) : error C2466: cannot allocate an array of constant size 0

c:Code(6) : error C2133: 'b' : unknown size


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
August 07, 2008 03:20:58   #2  
kalai4best Member Since: August 2008   Contribution: 2    

RE: What will be difference b/w 5th and 6th statements?
max can be used only within the main() and has a impact within that. But MAX can be used in any kind of user defined functions.
 
Is this answer useful? Yes | No
September 19, 2008 03:17:19   #3  
mayankjaan Member Since: September 2008   Contribution: 1    

RE: What will be difference b/w 5th and 6th statements?

On 5th statement work fine.

But on 6 the statement it gives compilation error.


error C2057: expected constant expression

error C2466: cannot allocate an array of constant size 0

error C2133: 'b' : unknown size


Conclusion:

The macro value expansion done at compilation time but the assignment of
variable value at run time.

Also the array has property to assign constant value not and variable value


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape