Which one is correct to declare & initialize array in C?

A

int arr(5) = {1,2,3,4,5};

B

int arr[5] = {1,2,3,4,5};

C

int arr( ) = 1,2,3,4,5; 

D

Array arr(5) = {1,2,3,4,5};

উত্তরের বিবরণ

img

Answer: ) int arr[5] = {1,2,3,4,5};

  Explanation:
In C programming, the correct syntax to declare and initialize an array is:

 int arr[5] = {1, 2, 3, 4, 5};
int → data type
arr → array name
[5] → size of array
{1,2,3,4,5} → initialization list
 
Incorrect options:
() int arr(5) → wrong syntax (parentheses are used for functions, NOT arrays).
() int a( ) = 1,2,3,4,5; → invalid array syntax.
() Array arr(5) → not valid in C (this looks like C++ syntax).

 

Unfavorite

0

Updated: 2 days ago

Related MCQ

 The Principal of Locality in memory systems helps to: 

Created: 2 days ago

A

Reduce CPU clock cycles

B

Improve cache performance

C

Increase instruction length

D

Reduce I/O latency

Unfavorite

0

Updated: 2 days ago

Which phase in the compiler design performs data type checking?

Created: 2 days ago

A

Lexical analysis 

B

Syntax analysis

C

Semantic analysis

D

Code generation

Unfavorite

0

Updated: 2 days ago

 Which one is true for a B+ tree? 

Created: 2 days ago

A

Internal nodes store only actual data

B

Leaf nodes store actual data

C

Does not maintain sorted data

D

Retrieval of data is slower

Unfavorite

0

Updated: 2 days ago

© LXMCQ, Inc. - All Rights Reserved

Developed by WiztecBD