hai
i am mithra. i have one doubt in c Array declaration.
<CODE>
#include<stdio.h>
main()
{
int a[10];int i;
for(i=0;i<20;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<20;i++)
{
printf("%d",a[i]);
}
}
</CODE>
In this code i just declared 10 elements of array. but i gave 20 elements as an input. it can accept it. it does not generate any errors. it just print the 20 elements so when the memory is allocated? is it in declaration or not
please clarify my doubt
3 2131
hai
i am mithra. i have one doubt in c Array declaration.
<CODE>
#include<stdio.h>
main()
{
int a[10];int i;
for(i=0;i<20;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<20;i++)
{
printf("%d",a[i]);
}
}
</CODE>
In this code i just declared 10 elements of array. but i gave 20 elements as an input. it can accept it. it does not generate any errors. it just print the 20 elements so when the memory is allocated? is it in declaration or not
please clarify my doubt
You were just lucky; your program used part of a stack that didn't belong to your
process. You were just lucky that nothing else needed that part of the stack.
Crossing array boundaries causes undefined behaviour. Anything could have
happened, like daemons flying out of your nose ;-)
kind regards,
Jos
You were just lucky; your program used part of a stack that didn't belong to your
process. You were just lucky that nothing else needed that part of the stack.
Crossing array boundaries causes undefined behaviour. Anything could have
happened, like daemons flying out of your nose ;-)
kind regards,
Jos
But, when I am running the same program, after entering 19 values, it gives segmentation fault. How does the same program run with different behaviours?? Can it change the behaviour of array?
Regards
But, when I am running the same program, after entering 19 values, it gives segmentation fault. How does the same program run with different behaviours?? Can it change the behaviour of array?
Regards
An excellent example of undefined behaviour. Anything could have happened.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: User |
last post by:
Hi,
This is very basic, It may be a repost, if so I'm sorry.
The problem is that this declaration :
Private strMyArray(100) As String
will create an array of string with a length of 101,...
|
by: Sam |
last post by:
Hello all
I have a two dimensional array (the dimensions are not known) that
needs to be passed
to fortran from c++, allocate the dimensions of the array in fortran
code, do some filling up
of...
|
by: songkv |
last post by:
Hi,
I am trying to reassign an array of char to a string literal by
calling a function.
In the function I use pointer-to-pointer since I want to reassign the
"string array pointer" to the string...
|
by: pandapower |
last post by:
Hi,
I know about the equivalence of pointer and arrays.But my doubt
comes when its for multidimentional arrays.I have read the C faq but
still have some doubts.
Suppose I have a declaration as...
|
by: intrepid_dw |
last post by:
Hello, all.
I've created a C# dll that contains, among other things, two functions
dealing with byte arrays. The first is a function that returns a byte
array, and the other is intended to...
|
by: joshc |
last post by:
Hi,
I have an array defined in one file with an intializer as follows:
int arr = {0, 1, 2, 3};
I have a declaration of the array in another file as follows:
extern int arr;
|
by: DarelRex |
last post by:
Is it possible to pass a 2-D, statically defined array?
Here's a 1-D example that won't work:
void foo() {
int myArray ;
bar(myArray);
}
void bar(int *arr) {
|
by: =?Utf-8?B?U2hhcm9u?= |
last post by:
Hi Gurus,
I need to transfer a jagged array of byte by reference to unmanaged
function, The unmanaged code should changed the values of the array, and when
the unmanaged function returns I need...
|
by: mdh |
last post by:
>From p112 ( K&R).
Given an array declared as
static char arr= { { 0,1,........},{0,1,.....}};
let arr be passed as an argument to f.
f( int (*arr) ) {....}
It is noted that the...
|
by: aruna.mysore |
last post by:
Hi all,
I have a specific problem passing a function pointer array as a
parameter to a function. I am trying to use a function which takes a
function pointer array as an argument. I am too sure...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |