All Questions
372 questions
0
votes
1
answer
71
views
Why does a pointer to the first element of an array, after dereference, evaluates to the third element? [duplicate]
It dereferences to the third element when I'm trying to do it inside printf(), where I also try to dereference that pointer with post and pre-increment.
Here's my code:
#include <stdio.h>
int ...
0
votes
2
answers
103
views
why printf can not print string of a pointer?
I write this program for print content of a string in c language.
but dont print string!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define GROW_BY 10
int main(){
...
1
vote
1
answer
115
views
Expression evaluation in printf with %p
I am studying pointers in C. Trying a bunch of things to make sure I understand how pointers work, I found something that I don't understand. Here's the snippet of the code in question:
int b = 30;
...
1
vote
1
answer
83
views
Initializing a Variable for Strings Using Ternary Operators in C
So I want to set strings as my variables' value which is dependent on some other test cases.
const char* trial_1;
const char* trial_2;
const char* trial_3;
trial_1 = (...
1
vote
1
answer
101
views
printf() function with some "relationship" with my pointers struct in C
i was studying the C language and this power in memory management,(in this case i was studying the creation of Stack data structure in C), but when i was refactoring my code (deleting the useless ...
1
vote
1
answer
131
views
Uninitialized value error when accessing array bytes via pointer arithmetic in C
I'm working on a C program where I need to display the byte values of an integer array. Here's the code I'm using:
#include <stdio.h>
int main(void)
{
int arr[] = {67305985, 134678021, ...
1
vote
2
answers
118
views
My code keeps segfaulting whenever I try to print strings
I'm working on a game to run in the Linux Terminal. I've been working on a system to load in a map file, turn it into a string of custom structs, and then print the letter and color that the ...
2
votes
2
answers
207
views
Printing pointers itself in C
I am new to programming in C and I am trying to understand the concept of pointers. However, the result of some print statements are quite confusing and I was not able to find suitable answers online.
...
0
votes
3
answers
230
views
Not able to print the absolute address of global variable address
Baremetal riscv gcc compiled code and linked. I can load my program at any address. firmware calls my program using pointer to my function. I am not able to print the global variables address, its ...
2
votes
3
answers
173
views
Difference between & address and pointer address- Hexadecimal and pointer type data [duplicate]
I am using the following piece of code as a learning exercise for pointers:
int a=8;
int *ptr=&a;
printf("\nThe & address of a is: %x\n",&a);
printf("\nThe value of the ...
0
votes
1
answer
320
views
Print char pointer array in a struct with printf in c
I am trying to print the names of my array with a for but the output gives me random letter and signs,
I cant cast it correctly to print the names of the struct.
typedef struct{
// uint8_t name;
...
0
votes
3
answers
349
views
Creating a simple printf function in C without using stdarg.h library
I've been working on making a very simple printf function in c that does the following: it prints strings, signed integers, unsigned integers and the % symbol. Every implementation I have checked uses ...
0
votes
1
answer
58
views
Last printf statement is being skipped
After insertting all my values I was expecting to have the final printf statement give the final results of the equations
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char ...
1
vote
3
answers
459
views
the size of distance between two pointers
void main() {
int a = 2;
int *p = &a;
int *q = p++;
printf("%d %d\n", p, q);
int b = p - q;
printf("%d", b);
}
Why does it print 1? I've tried with ...
0
votes
2
answers
105
views
How do I change contents of a variable using a pointer?
I'm working with pointers for the first time in C. I tried to declare, initialize, and assign a memory address to 3 pointers, then print the addresses and values of each pointer and variable, then ...