Error message

  • Deprecated function: Return type of DatabaseStatementBase::execute($args = [], $options = []) should either be compatible with PDOStatement::execute(?array $params = null): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2244 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: Return type of DatabaseStatementEmpty::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in require_once() (line 2346 of /home2/psicolog/public_html/feliponcho/includes/database/database.inc).
  • Deprecated function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in drupal_random_bytes() (line 2268 of /home2/psicolog/public_html/feliponcho/includes/bootstrap.inc).
  • Deprecated function: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in url() (line 2349 of /home2/psicolog/public_html/feliponcho/includes/common.inc).
  • Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in url_is_external() (line 2393 of /home2/psicolog/public_html/feliponcho/includes/common.inc).
  • Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in url_is_external() (line 2395 of /home2/psicolog/public_html/feliponcho/includes/common.inc).
  • Deprecated function: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in url() (line 2311 of /home2/psicolog/public_html/feliponcho/includes/common.inc).

Pointers in C

Pointers

Variables

To understand pointers let´s review first the concept of variable.

  • A variable has a name, and address, a type and a value:
    • The type specifies how to interpret the data stored in main memory during execution and the size of the variable.
      • If you are going to store lions then you need big cages designed for lions
      • Analogically, if you are going to store doubles then you need 8 bytes to store a double value.
      • If you are going to store squirrels then you need small cages designed for squirrels.
      • Analogically, if you are going to store unsigned chars then you need 1 byte in memory to store an unsinged char.
    • The value is the actual data stored in the variable after it has been interpreted according to a given type.
      • Leo the lion
      • 1234.32342
      • Dale the squirrel
      • 2
    • The address specifies where in main memory the variable is located.
      • In the zoo all the cages have a number.
        • The cage of Leo the lion is the number 3234.
      • In the memory all the variables have an address.
        • The address where 1234.32342 is stored is 0xA0239201
    • The name identifies the variable to the programmer.
      • For easy reference the zoo employees refers to Leo´s cage as "the cage of the Lion"
      • For easy reference the programmer refers to 0xA0239201 as local_float_variable

Pointers

Now that we understood that all variables have a memory address, you should know that we can manipulate the values of that variable directly by using the address.

As variables are friendly names for the data stored in them, Pointers are friendly names for the addresses in memory where the data is stored.

Thus, a pointer is a variable where we can store data addresses

  • We can store the address of local_float_variable in a pointer named pointer_to_float_variable
  • Example
    float local_float_variable = 1234.32342;
    float *pointer_to_float_variable; /*This is the pointer declaration, note that this pointer can only point to addresses storing float data*/
    pointer_to_float_variable = &local_float_variable; /*Here we get the address of local_float_variable and store it in pointer_to_float_variable*/
    *pointer_to_float_variable += 1; /*Here we modify the float value, now it becomes 1235.32342*/
    

Pointer Operators

We have two operators for working with pointers:

  • &
    • this operator is useful when we have a variable and we want to know it's memory address.
    • This operator is known as:

      the address of...

    • Example
      printf ("the address of local_float_variable is: \n",&local_float_variable);
      
  • *
    • we use this operator when we have a pointer and we want to know the data pointed by this pointer.
    • This operator is known as indirection operator. I name this operator

      the data pointed by...

    • Example
      printf ("the data pointed by pointer_to_float_variable is: \n",*pointer_to_float_variable);