Mistake 1 .Constant Expression Require
#include<stdio.h>
void main()
{
int i=10;
int a[i];
}- i is initialized to 10.
- Using a[i] does not mean a[10] because 'i' is Integer Variable whose value can be changed inside program.
#include<stdio.h>
void main()
{
const int i=10;
int a[i];
}because -- Value of Const Variable cannot be changed once initialized.
Mistake 2 .Empty Valued
#include<stdio.h>
void main()
{
int a[];
}- a is Unknown Here or Empty.
- Size of Array should be Specified as a Constant Value.
#include<stdio.h>
void main()
{
int a[] = {1,1};
}- After writing it default size of Array is 2.
#include<stdio.h>
void main()
{
int a[] = {}; // This also Cause an Error
}Mistake 3 .Does Not Checks Bound Checking
#include<stdio.h>
void main()
{
int a[5];
printf("%d",a[7]);
}- Here Array size specified is 5.
- So we have Access to Following Array Elements - a[0],a[1],a[2],a[3],a[4]
- But accessing a[5] causes Garbage Value to be used because C Does not performs Array Bound Check.
- So One Should access values upto [Maximum - 1]
Mistake 4 .Case Sensitive
#include<stdio.h>
void main()
{
int a[5];
printf("%d",A[2]);
}- Array Variable is Case Sensitive so A[2] does not print anything it Displays Error Message : "Undefined Symbol A"
Some Tips :
Tip 1 : Use #define to Specify Array Size
#include<stdio.h>
#define MAX 5
void main()
{
int a[MAX];
printf("%d",a[2]);
}- As MAX is replaced by 5 for every Occurrence , So In due Course of time if you want to increase or decrease Size of array then change should be made in
Tip 2 : a[i] and i[a] are Same#define MAX 10
Back to Category

0 comments
Post a Comment
Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email