Sponsored Content
Full Discussion: Pointers and array
Top Forums Programming Pointers and array Post 302857145 by Corona688 on Wednesday 25th of September 2013 01:07:17 PM
Old 09-25-2013
Quote:
Originally Posted by yifangt
Here it is very interesting the index can be negative. Amazing C!
That's just how the processor, and two's-complement math works, not a special property of C per-se. It lets you do so, when most languages would protect you from it, but C, which hardcodes so much into assembly language at compile-time (same reason sizeof() can't be used dynamically) is very limited in what it can warn you about.

In most situations, a negative array index would edge into incorrect or even invalid memory, causing strange behavior or crashes. It's only okay here since you know you're not at the beginning of the data of interest.

So, use with care.
 

10 More Discussions You Might Find Interesting

1. Programming

Pointers and array

hi all, let say i have a pointer exit, and this exit will store some value. how can i store the value that the pointer points to into an array and then print them out from the array. thanks in advance (2 Replies)
Discussion started by: dianazheng
2 Replies

2. Programming

pointers

is this a valid c declaration int (*ptr(int *b)); plz explain... (4 Replies)
Discussion started by: areef4u
4 Replies

3. Programming

pointers

Hi I mash with pointers in C. I solve this problem about 5 hours and I don't know how I should continue. void InsertFirst (tList *L, int val) { tElemPtr new; if((new = malloc(sizeof(tElemPtr))) == NULL) Error(); new->data = val; new->ptr = L->frst; L->frst = new;... (2 Replies)
Discussion started by: Milla
2 Replies

4. Programming

restricted pointers

Hi all. I am trying to use restricted pointers to allow the gcc compiler optimize the code, but I have not been able to make it work so far. I am testing with this code: #include <stdlib.h> #include <stdio.h> #include <time.h> #include <sys/time.h> void vecmult(int n, int * restrict a, int... (0 Replies)
Discussion started by: carl.alv
0 Replies

5. UNIX for Advanced & Expert Users

shared pointers

I am new to shared pointer conceot in C++ and hence require some clarification: For example: class A { public: virtual ~A() { } int x; }; typedef boost::shared_ptr<A>... (1 Reply)
Discussion started by: uunniixx
1 Replies

6. Programming

Need help with the Pointers in C

I have a special character called ô. When it is declared as a character variable its showing it can be printed. But when it is declared as a character pointer variable its showing it cannot be printed. I am just wondering why its happening like this.. c1 = '@'; c2 = 'ô'; char *fp; fp="XXô"; if... (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

7. Programming

Problem with array of pointers

Hi All, I am using the array of pointers and storing the address of string.This is a global list. So i am using extern to give the reference of this list to another file and using reading the data from this string. But list is being corrupted and string is missing some characters in... (2 Replies)
Discussion started by: lovevijay03
2 Replies

8. Programming

Traversing in Array of pointers

Please find the below program. the requirement and description of the program also given: ganesh@ubuntu:~/my_programs/c/letusc/chap9$ cat fa.c.old /* Program : write a program to count the number of 'e' in thefollowing array of pointers to strings: char *s = { "We will teach you how... (12 Replies)
Discussion started by: ramkrix
12 Replies

9. Programming

Problem With Pointers

Hi guys. What is the difference between these: 1. int *a; 2. int (*a); (2 Replies)
Discussion started by: majid.merkava
2 Replies

10. Programming

How to Declare an array of function pointers?

I am attempting to create an array of function pointers. The examples I follow to do this are from: support.microsoft.com/en-us/help/30580/how-to-declare-an-array-of-pointers-to-functions-in-visual-c ... (3 Replies)
Discussion started by: spflanze
3 Replies
ARRAY_INTERSECT(3)							 1							ARRAY_INTERSECT(3)

array_intersect - Computes the intersection of arrays

SYNOPSIS
array array_intersect (array $array1, array $array2, [array $...]) DESCRIPTION
array_intersect(3) returns an array containing all the values of $array1 that are present in all the arguments. Note that keys are pre- served. PARAMETERS
o $array1 - The array with master values to check. o $array2 - An array to compare values against. o $... - A variable list of arrays to compare. RETURN VALUES
Returns an array containing all of the values in $array1 whose values exist in all of the parameters. EXAMPLES
Example #1 array_intersect(3) example <?php $array1 = array("a" => "green", "red", "blue"); $array2 = array("b" => "green", "yellow", "red"); $result = array_intersect($array1, $array2); print_r($result); ?> The above example will output: Array ( [a] => green [0] => red ) NOTES
Note Two elements are considered equal if and only if (string) $elem1 === (string) $elem2. In words: when the string representation is the same. SEE ALSO
array_intersect_assoc(3), array_diff(3), array_diff_assoc(3). PHP Documentation Group ARRAY_INTERSECT(3)
All times are GMT -4. The time now is 12:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy