0

here's a code I wrote

    int main(){
    char arr[50][*];
    arr[0][0]=1;
    if(arr[0][1]){
    printf("%d",arr[0][0]);}

If I am putting 1 as *, there is no output. but anything greater than 1 in the array size would result in 1 output.that means when I am declaring array size the elements are occupied by some value.

now, my actual need is to write a condition if loop (example)

if(arr[0][1]!='null') // or '0',false,undefined, etc

but I am confused what is there in that empty but declared element, because the above is not working.

3
  • 1
    you have not initialized the arr, so cannot say what gets printed Commented Nov 12, 2020 at 4:33
  • 1
    This question has explained answer for your question answer Commented Nov 12, 2020 at 4:43
  • 1
    please properly ident your code. Commented Nov 12, 2020 at 14:55

2 Answers 2

4

There is no default value.

For an object defined inside a function without the static keyword, the initial value is garbage.

You can't test an object to determine whether it's been initialized or not. You have to write your code to avoid reading any object's value before it's been set.

Sign up to request clarification or add additional context in comments.

3 Comments

actually I was trying to print an array whose size I don't know
@mr.loop The code in your question doesn't show an array whose size you don't know. I can only answer the question you asked.
let me rephrase that. I wanted to print an array whose number of initialized or defined elements I don't know. anyways, i got the answer.
1

doing(while declaring),

char arr[50][2]={0}  //or whatever the size of 2nd dimension other than 2

this will replace all elements(100 in this case) with 0.

So, according to my necessity,I can do

if(arr[0][1] != 0)

for checking if that element is undefined by me. this example works when your input doesn't contain 0, if it does replcae all elements with something else and also the condition too

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.