Pointers in C: Is cell=&num equivalent to *cell=num? [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Suppose you have the variable int num and the pointer int* cell. Does it make a difference for the values stored in cell and num to write cell = &num or *cell = num?

cell = &num
means that the contents/value of cell will be equal to the address of num.
*cell = num
means that the content at the address stored in cell, that is the value to which the pointer is pointing to, will be equal to the value of num.

Related

assign zero to item in char array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I have some materials showing this code. what does code means by making these assignments?
char inputfilename[128];
inputfilename[0] = 0;
char *argv[128];
*argv[1] = 0;
In C, character arrays are terminated by a null character (value 0). In both cases in your example, the code initializes the strings to "empty" (with a terminator in the first element). This would prove useful in any subsequent string operations (strcat, strcpy, etc.).

I need a variable that have a small range value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have an input number that it's value is not always consistent, i mean the value change plus 1 or minus 1 and etc. So, i want to compare it with a const but have a small range value, for example a const int Dist that have value between 14 to 16. Is that possible to implement it on C programming? Please help me.
You can set constant for lower bound, and constant for upper bound and check if the value falls within the range.
Pseudocode:
int const LOWER_BOUND = 14;
int const UPPER_BOUND = 16;
if (input <= UPPER_BOUND && input >= LOWER_BOUND)
... logic here ...

What does the following c code do? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
#define SRC_ASCLIN_ASCLIN0_RX (*(volatile Ifx_SRC_SRCR*)0xF0038084u)
Here SRC_ASCLIN_ASCLIN0_RX means ASCLIN(Async/Sync serial LIN Comm) Receive Service Request.
I know that the macro is used to point at the address 0xF0038084u. But I want real time examples.
Am working on UART development on Infineon microcontroller.
The macro, when expanded by the preprocessor, cast the integer literal as an address, a pointer to Ifx_SRC_SRCR, then dereferences the pointer so you can get or set the value of the memory stored at that specific address.
So you could write e.g.
Ifx_SRC_SRCR value = SRC_ASCLIN_ASCLIN0_RX;
or
SRC_ASCLIN_ASCLIN0_RX = some_other_value;
It basically equivalent to doing e.g.
int an_integer = 6;
int *pointer_to_an_integer = &an_integer;
*pointer_to_an_integer = 10; // Equivalent to SRC_ASCLIN_ASCLIN0_RX = some_other_value above

issue with array allocation using sizeof in C [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
mid= n / 2;//(where n is 10)
int left[sizeof(mid)];
but compiler allocate space for 4[0,1,2,3] elements, it suppose to allocate for 5[0,1,2,3,4] elements.
what could be the issue?
sizeof mean: the size in memory. int is 4 bytes in memory. so sizeof(int)=4.
You probably want to write int left[mid];

put integer into 4 char array elements [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
is there any way how to put integer sized 100 000 into 4 elements of char array? If I use sprintf or itoa, array has 6 elements. I tried to use this, but it didnt work. And is there any way how to put these 4 elements back to integer?
char *s;
int value = 100000;
*((int *)s)=value;
Note that:
int value = 100000;
char *s;
*((int *)s)=value;
dereferences uninitialized pointer s, which causes undefined behavior. You could do:
int value = 100000;
char s[4];
*((int *)&s[0])=value;
just note that this stores value in the memory block "occupied" by charr array (at memory level) unlike sprintf, which would print the value in a form of string (characters representing the number).

Resources