0% found this document useful (0 votes)
2 views5 pages

Invalid Array Syntax

The document outlines important points about arrays in C/C++ that students often overlook, such as the immutability of array names, the equivalence of a[i] and i[a], and the necessity of null characters in character arrays. It also discusses array size discrepancies, out-of-bounds behavior, and the limitations of copying arrays directly. These concepts are frequently tested in exams and are crucial for understanding array behavior in programming.

Uploaded by

treecraftlegends
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Invalid Array Syntax

The document outlines important points about arrays in C/C++ that students often overlook, such as the immutability of array names, the equivalence of a[i] and i[a], and the necessity of null characters in character arrays. It also discusses array size discrepancies, out-of-bounds behavior, and the limitations of copying arrays directly. These concepts are frequently tested in exams and are crucial for understanding array behavior in programming.

Uploaded by

treecraftlegends
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Anudeshak, DSA aur C/C++ exams me arrays ke kuch aise points hote hain jo

bahut students miss kar dete hain:

1. Array Name Constant Pointer Jaisa Hota Hai

int a[5];

a = a + 1; // ❌ Error
Lekin:

int *p = a;
p = p + 1; // ✅ Valid
Array ka naam modify nahi ho sakta.

2. a[i] aur i[a] Dono Same Hain

int a[] = {10,20,30};

printf("%d", a[1]);
printf("%d", 1[a]);

Dono output:

20

Kyuki:

a[i] = *(a+i)
i[a] = *(i+a)
3. Array Index Negative Bhi Ho Sakta Hai

int a[5];
int *p = &a[2];

printf("%d", p[-1]);

Ye a[1] access karega.

4. sizeof(a) aur sizeof(&a) Alag Hote Hain

int a[10];

Agar int = 4 bytes

sizeof(a) = 40
sizeof(&a) = 8 // 64-bit system

5. Character Array me Null Character Zaroori Hai

char s[] = "ABC";

Memory:

A B C \0

Size:

sizeof(s) = 4
6. Array Out of Bounds Error Nahi Deta

int a[3] = {1,2,3};

printf("%d", a[10]);

Compile ho jayega, lekin result undefined hai.

7. 2D Array Memory me Continuous Hoti Hai

int a[2][3];

Memory:

a[0][0] a[0][1] a[0][2] a[1][0] a[1][1] a[1][2]

Row-major order.

8. Initialization me Missing Values 0 Ban Jati Hain

int a[5] = {1,2};

Actually:

{1,2,0,0,0}

9. Array Copy Directly Nahi Kar Sakte

int a[5], b[5];

b = a; // ❌ Error
Loop ya memcpy() use karna padta hai.

10. sizeof Function Parameter Wale Array Par Kaam Nahi Karta

void fun(int a[])


{
printf("%d", sizeof(a));
}

Yahan a array nahi, pointer ban jata hai.

64-bit system par:

print hoga, poore array ka size nahi.

11. Sabse Famous MCQ

int a[5] = {1};

Array:

{1,0,0,0,0}

Bahut students {1,1,1,1,1} samajh lete hain.

12. String Literal Modify Nahi Kar Sakte

char *s = "Hello";
s[0] = 'Y';

❌ Undefined behavior.
Lekin:
C

char s[] = "Hello";


s[0] = 'Y';

✅ Valid.
Ye points exam MCQs me bahut baar pooche jaate hain aur kaafi students ko nahi pata
hote.

You might also like