5:00 int arr[10] = {}; works in 2023. The c complier may be updated. I tested this using both gcc and clang. Here is the test code : #include int main() { int a[10] = {}; for ( int i = 0; i < 10; i++ ) printf("a[%d] = %d ", i, a[i]); return 0; }
A small correct at 5:20 The statement `int arr[10] = {};` is legal in C, but its interpretation and behavior might not be immediately clear to all compilers, depending on the C standard they adhere to. Explanation: 1. **C99 and later**: - In C99 and later standards, you can initialize an array with `{}`. This is called a "universal zero initializer". It means that all elements of the array will be initialized to zero. - The statement `int arr[10] = {};` will initialize all elements of `arr` to `0`. 2. **Pre-C99**: - In C89/90 (the earlier C standard), the empty braces `{}` as an initializer might not be explicitly supported, and this could lead to a compiler error or warning. - Instead, you would typically initialize an array explicitly or with `{0}`: ```c int arr[10] = {0}; // All elements initialized to 0. ``` Example in Code: ```c #include int main() { int arr[10] = {}; // Legal in C99 and later for(int i = 0; i < 10; i++) { printf("%d ", arr[i]); } return 0; } ``` Compatibility: - If you are using a compiler that supports C99 or later, the code should compile and run without issues, initializing all elements to zero. - If using an older compiler that does not support C99, you may get an error or warning. In such cases, use `int arr[10] = {0};` for compatibility. ### Conclusion: - `int arr[10] = {};` is legal and initializes all elements to zero in C99 and later. - For maximum compatibility with older C standards, use `int arr[10] = {0};`.
Hey, at 3:45 the garbage value at first gives 0 for the length if it exceeds by 1 but if I use more memory for rest of the unspecified bits it gives/allocates some garbage value to the array.
Write a program that initialize array of size 10, and prints all Armstrong and Palindrome numbers in array. Your program should ask user about their choice of printing. If user press ‘A’ or ‘a’ then program should display all Armstrong numbers in array and if user press ‘P’ or ‘p’ then it should display all Palindrome numbers in array.
in the topic Initializing Array @5:17 to 5:25. you mentioned that you cant add more elements to an array than the specified size of the array. This happens to not be the case as C actually allows you to add more elements than the size array which of course could lead to a lot of problems but I think its worth noting as it appears to be a weakness with the c programming language
if you write int arr[SIZE] = {0}; Only the first element will get the value zero and the rest are filled automatically by the compiler, try changing 0 to 1 and see the difference
Sir, first of all, thank you that you make such good videos for us free of cost, but sir, I have a request that along with understanding, please provide us notes to write in the exam, because i dont know how to write in the exam.
If I declare an array of type float and initialise the first value as 0.0f. Will the rest of the values also be initialised as 0.0f? Example: float array[5] = {0.0f}; The reason I ask is because I'm working with a microcontroller and calculations on a float value will be done with double precision and not single precision unless I specify 0.0f and I don't need the extra accuracy but need to save computation time.
hi! just came across this video while roaming around, am very interested in learning programming, and was looking for definition of an array, any advise where can I start ?
1) int arr[5]; arr[5]={1,2,3,4,5}; Why is this code showing error? 2) int ar[5]={}; Sir, even this code works fine in VS code.....in fact, this is the easiest way to initialize an array with all zero.
We cannot initialize and declare arrays separately like that. U can do only if u are assigning one element at a time. Ex : int arr[5]; arr[0] = 1; arr[1] = 2; arr[2] = 3; arr[3] = 4; arr[4] = 5;
@@meowrbius arr[5] means you are accessing the 5th index of arr array(actually not initialising the array), If you have already declared array then you have to use method-3,4 not 1, to declare, define and intialize you can do int arr[5] = {1 ,2, 3, 4, 5}
Videos from Neso Academy are absolute gold. Pure concept.
Great sir. Neso Academy's way of explanation is really exciting. Would love to see you get more views by people such as me❤
5:00 int arr[10] = {}; works in 2023. The c complier may be updated. I tested this using both gcc and clang. Here is the test code : #include
int main()
{
int a[10] = {};
for ( int i = 0; i < 10; i++ ) printf("a[%d] = %d
", i, a[i]);
return 0;
}
thank you so muuuuch from Germany Sir
i m from nepal & its helping us a lot! thank you very much sir
A small correct at 5:20 The statement `int arr[10] = {};` is legal in C, but its interpretation and behavior might not be immediately clear to all compilers, depending on the C standard they adhere to.
Explanation:
1. **C99 and later**:
- In C99 and later standards, you can initialize an array with `{}`. This is called a "universal zero initializer". It means that all elements of the array will be initialized to zero.
- The statement `int arr[10] = {};` will initialize all elements of `arr` to `0`.
2. **Pre-C99**:
- In C89/90 (the earlier C standard), the empty braces `{}` as an initializer might not be explicitly supported, and this could lead to a compiler error or warning.
- Instead, you would typically initialize an array explicitly or with `{0}`:
```c
int arr[10] = {0}; // All elements initialized to 0.
```
Example in Code:
```c
#include
int main() {
int arr[10] = {}; // Legal in C99 and later
for(int i = 0; i < 10; i++) {
printf("%d ", arr[i]);
}
return 0;
}
```
Compatibility:
- If you are using a compiler that supports C99 or later, the code should compile and run without issues, initializing all elements to zero.
- If using an older compiler that does not support C99, you may get an error or warning. In such cases, use `int arr[10] = {0};` for compatibility.
### Conclusion:
- `int arr[10] = {};` is legal and initializes all elements to zero in C99 and later.
- For maximum compatibility with older C standards, use `int arr[10] = {0};`.
found this after my mid sem , hopefully ill ace my end sem by learning from this , hats off to u sir, ur infinite times better than my teacher !
How is it going?
you fail!!
Always respect your teacher.
@@andistheinforitbutso7513 shut up
@@subhathishvenkata3716 ok burbook
Programming can't be more easier how you making this!❤️❤️❤️
Hey, at 3:45 the garbage value at first gives 0 for the length if it exceeds by 1 but if I use more memory for rest of the unspecified bits it gives/allocates some garbage value to the array.
Sir u are a genius in explaining and this channel is great
I m now doing my 1semister of my CSE the best explanation...that I have seen
Thanku for ur clear voice and explanation sir
Sir at 3:40 my sir told that it store garbage value instead of 0's to save time and working 🙄
Other please correct me🙏all who ever know this
Great sir we are lucky to have a teacher like you ❤
Sahi insaan ko pakda maine ab c sikhne ke liye 🤗thank u soo much 💖
Also please upload pointers, structures and data structure implementation in c(tree, stack, queue, link list, malloc etc..) Thank you
Sir it's my heartiest request plz upload regularly my interview are near
What are you doing now? Any job aur interview ka kya hua 😮
Write a program that initialize array of size 10, and prints all Armstrong and Palindrome numbers in array. Your program should ask user about their choice of printing. If user press ‘A’ or ‘a’ then program should display all Armstrong numbers in array and if user press ‘P’ or ‘p’ then it should display all Palindrome numbers in array.
in the topic Initializing Array @5:17 to 5:25. you mentioned that you cant add more elements to an array than the specified size of the array. This happens to not be the case as C actually allows you to add more elements than the size array which of course could lead to a lot of problems but I think its worth noting as it appears to be a weakness with the c programming language
Thanks a lot sir... I barely got any doubt in this topic now
in method 1 and 2 how can you initialize array not at declaration?
will you please provide the tutorials of Design analysis and algorithm?
why increment in method 4 in initialising a 1d array
4:51 its not illegal it works actually it will be filled by value of zero
You are excellent man, keep up the good work 👍👍
sir that's truth.. sir you are genius on c programming.. sir your explanation is awesome for students.. 😊
please checkout my channel i teach C in hindi with codes i make and i will make them in front of you not any presentation.
Perfect explaination 👌👌
int a[5]={}; still initializes all array elements to zero why is this illegal?\
Sir you are the best with your wonderful explaination and clear👍👍🤗
Doing great job brother 👍
Great lectures Sir, this is so detailed.
Is it possible to declare a 1D array like so;
int arr[] = {0};
yes of course it is a valid element. 0 is of data type int so it is a valid array arr[]
Thank you so so much sir😊👍
Sir if
Int arr[5]={1,2};
Then remaining three array position will be Zero
What about memory stored it would be 20 bytes or 8 bytes
Thanks teacher your very helpful ..
thank-you so much sir you help a lot of people by this video
thank you so much sir greetings from usa this is the exact quick answer i was looking for! :D
Very well explained.. Thank u
thank you so much i enjoy programming bc of you!!!
if you write
int arr[SIZE] = {0};
Only the first element will get the value zero and the rest are filled automatically by the compiler, try changing 0 to 1 and see the difference
Great sir❤
Nice video sir.. If possible plz upload video fast
Awesome content an d good explanation too..
Thanks for the uploaded this video🙏
Sir, first of all, thank you that you make such good videos for us free of cost, but sir, I have a request that along with understanding, please provide us notes to write in the exam, because i dont know how to write in the exam.
Very Helpfull Lecture
can u give a example for this int arr[10]={0}; code
1:33 In method 1 and 2, data type for array is not written. But is it possible to declare and initialize arrays separately like that ?
int arr[10] = {}; is legal when compile by GCC
Sir , by keeping array size empty we can store any number of values
Nice, keep up the good work.
You are good, sir, I am just smiling😁
Will cops invade my house if I add more elements than mentioned?
Yes you are sentenced to watch 10 hour skibbidi toilet
Due to your good behaviour you are now released
Yes
❤❤❤ from odisha
How can i get numbers in a array string if the numbers are between spaces?
Example:
Array string = { "12 3 20"}
Really it helps me a lot
Can you explain about global array? please
Can you make lectures on python and it’s data structures too
Very nice sir
sir in 1st and 2nd method you didnt declare type of an array it is correct or not?
sir but when input is greater than the length of the array,it's workinf fine It's not showing any error
If I declare an array of type float and initialise the first value as 0.0f. Will the rest of the values also be initialised as 0.0f? Example: float array[5] = {0.0f}; The reason I ask is because I'm working with a microcontroller and calculations on a float value will be done with double precision and not single precision unless I specify 0.0f and I don't need the extra accuracy but need to save computation time.
verry verry nice video sir thanks.
Please explain the 4method of array please🙏🙏🙏🙏🙏
How can we write if we want to initialise all elements of the array with a number other than zero
Sir ur much better than my hod
waiting for u r next videooo....if u fastly upload u r videos it will helpfull for those people who are now learn c...
what happens when we directly print an array.. please reply
Thanks a lot sir
hi! just came across this video while roaming around, am very interested in learning programming, and was looking for definition of an array, any advise where can I start ?
maybe you can start with learning c language
Thank you
How to initialize array of string?
string arr[] = {a, b, c, d};
I do this but it's error
Please Make Such Courses for C++ !!
please checkout my channel i teach C in hindi with codes i make and i will make them in front of you not any presentation.
How to use pointer aary in function ?please make video on it sir.
Sir what means by creating of array
You r just awsome!!🤯
what if we add more values than the size of the array
The automatic inicilization with value = 0, does it work only with global variables o with locals also?
simple explanation👍
Why was rest of the elements are zero.is there any chance the rest of the elements becomes garbage values?
The illegal cases that u explained are not illegal at all. They are working just fine
Very useful for me.
Very good dada,,,,,
In method 2, there should be data type involved...
I am beginner. Sadly unable to find series of lectue
What's index means
Thanks sir
Thank u
int arr[10]={0};
int arr[10]={1};
if all ten elements are 1,can i express the way above?
No 1 value will allocated to first block other will get 0 values
@@anjaliverma7949 any way to initiate the array with -2 of size 1lack
Oh Man you are Great
sir can you kindly add links to the source code
arr[10]; will also make all elements zero;
1) int arr[5];
arr[5]={1,2,3,4,5};
Why is this code showing error?
2) int ar[5]={};
Sir, even this code works fine in VS code.....in fact, this is the easiest way to initialize an array with all zero.
We cannot initialize and declare arrays separately like that. U can do only if u are assigning one element at a time.
Ex :
int arr[5];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
arr[3] = 4;
arr[4] = 5;
@@meowrbius arr[5] means you are accessing the 5th index of arr array(actually not initialising the array), If you have already declared array then you have to use method-3,4 not 1, to declare, define and intialize you can do int arr[5] = {1 ,2, 3, 4, 5}
@@darshanjaviya4770 yea.
And in the video, he is saying no need to write data type in method 1. That's wrong actually
@@meowrbius yes I also noted that
I like this channel.. 👍👍👍
nice sir
How about that, is that legal?
👇
int arr[ ] = {0}
Good
please make it fast
Nice
How did Rony got placed in xyz company as a software engineer without even knowing that basic thing
Gjb sir