Independent Researcher
Question
Asked 28 January 2011
Negative indices in C
Hello Friends,
Anyone please explain to me what happens when i supply negative index in C array. I got garbage value when i tried it.
Most recent answer
Hi need a sample open source for document reconstructions.... with DP and prims algo in java.. Actually this real time proj based on forensic science... Can any one help plz come on chat in google mail
All Answers (11)
Jiwaji University
Array indices start from 0 in C++ , I guess C too..
try to convert negative indices into positive..
Array[(i* -1)] , where i :negative index..
University of Oklahoma
An array in most programming languages is just a contiguous area of addressable storage and the language, say C, Rexx, NetRexx/JAVA keeps track of each element's 'address' starting from zero. When you tell C to address a negative amount it obliges with whatever garbage was in storage preceding the array's storage area. Rexx and NetRexx are not so brutal. I'm not sure what JAVA does; In general, it follows C.
1 Recommendation
University of Oklahoma
No matter what the language, best practice is to check the array index before it is used to make sure it is within logical bounds.
Robert L Hamilton, Engineer
Richardson, Texas USA
if y'u are trying to get negative value the program itself is vague, or absurd, because negative statements are considered as junk statements in programming languages, only positive statements are considered in p languages, so y'ur question is vague.
Jawaharlal Nehru Technological University, Hyderabad
index of an array, actually points to a position relative to the base address of the array(.i.e address of a[0]). Therefore a[3] is a location 3 positions after a[0] or is equivalent to:
*p=&a[0];
*p++; *p++; *p++;
hence a[-2] implies
*p--; *p--; *p--;
which is still a memory location(provided it exists) nevertheless (and can therefore show the value at the location) , but is not a part of your logical array,a
Similar questions and discussions
How to predict residuals using multiple imputation data?
Bruno Jiménez
I would like to know what would be the best way to predict the residuals for a regression involving multiple imputations. To be more specific, I am using an income inequality measure as a dependent variable in a regression model extracted from the SWIID (https://fsolt.org/swiid/). Let's call this variable 𝑌𝑐𝑡, where 𝑐 indexes countries, and 𝑡 indexes time. There are 100 imputations for 𝑌𝑐𝑡, and I would like to know what is the best way of computing the residuals 𝜖𝑐𝑡 on a regression like this one: 𝑌𝑐𝑡=𝛽𝑋+𝜖𝑐𝑡. The 𝑋 vector is a vector of known, observed variables (not inputted). I have been thinking of running the model a 100 times, one for each of the multiple imputations of 𝑌𝑐𝑡, and creating a variable that captures all 100 versions of 𝜖𝑐𝑡, does this make any sense? I am using Stata to process my data and it does not allow a direct prediction of the residuals, answers in how to work around this issue in any programming language would be useful; however, I am looking for more of a theoretical explanation of the underpinnings of working with multiple imputed data.
Related Publications
An operational extensible language system is described. The system and its base language are appraised with respect to efficiency, flexibility, and utility for different categories of users.
New programming languages are usually designed because the designer is not satisfied with existing languages.
METATEM is really a paradigm for programming languages rather than one particular language. There are three basic principles:
The versions of METATEM described in [Barringer et al., 1989], [Finger et al., 1993], [Fisher and Barringer, 1991], [Fisher, 1993], [Reynolds, 1995], [Barringer et al., 1996) and [Reynolds, 1997) use the temporal languages P...