#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........

Recommended Answers

All 2 Replies

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.

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;

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.