Question: I want to run a function for each product in a custom php file in wordpress. I used foreach loop for the same. But unfotunately id didn't work. Need Help.

The code is:

```
<?php
require_once("../../../../wp-load.php");
global $product;

foreach($product as $offer){
update_views_meta($offer->id);
}
?>

```

Function runs when I put a perticular product id in the place of $offer->id. But can't fetch $product->id in this file.

Answer: 
A c-string is a series of char. Terminate by the char `'\0'`.

```
char *ptr = "ABCD";

```

Create an array of 5 chars. `{'A', 'B', 'C', 'D', '\0'}` somewhere in static memory and assign the address of the first char (aka. `'A'`) to ptr.

When you do

```
ptr = 'A';

```

You assign the **value** of `'A'` to `ptr`, It's not a valid pointer or c-string so [de-referencing](https://stackoverflow.com/questions/14224831/meaning-of-referencing-and-dereferencing) the pointer cause an undefined behavior.

Plus, C is a typed language you can't put anything in anything. It's no guarantee that after assign `'A'` to `ptr`. That `ptr` will be equal to `'A'`. `ptr` has type `char *`, `'A'` has type `char`. You can't mix these types.

```
char *ptr = 'A';
if (ptr == 'A') // this is undefined behavior
  *ptr; // same here

```

Here what you must write if you want do what you try.

```
char c = 'A';
char *ptr = &c; // here ptr is not a valid c-string, it's just a pointer for one char

printf("%c", *ptr);

```
Here ptr points to a location in the data section(Read-only) section of the program.
You modified ptr='A'; Here ptr points to ascii value i.e 65 .So ptr points to the value at 65 location hence an undefined behavior