0
#include<stdio.h>

int main()
{
    int yo[4][4];
    int b;
    int c;
    
    
    for(b=0;b<12;b++)
    {       
            c=0;
            while(c<5)
            {
                yo[b][c]=(b*c);
                printf("a[%d][%d]  =   %d\n",b,c,(yo[b][c]));
                c++;
            }
    }
    getchar();
    return(0);
}

The above code starts with b=7 why!!!!!!

compile the programme and u will understand my problem ..
plz
helpp......

help...
Thnx in advance........

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by xavier666
0

Your array is [4][4] which means it has index 0-3. Both your loops will exceed this limit and will result in undefined behavior.

0

LINE 13 - while(c < 5)
When c = 4, array index is out of its bounds. The problem with C is that it C will not check for such array out of bounds conditions. The program will compile and run but will give the error at the end of its execution
LINE 10 - for(b=0;b<12;b++)
Any particular reason for giving 12? Again another array out of bounds...
Here is your corrected program...

#include<stdio.h>

int main()
{
	int yo[4][4];
	int b;
	int c;

	for(b = 0; b < 4; b++)
	{
		c = 0;
		while(c < 4)
		{
			yo[b][c] = b*c;
			printf("a[%d][%d]  =   %d\n",b,c,(yo[b][c]));
			c++;
		}
	}

	getchar();
	return 0;

}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.