Questions tagged [c]

Programming questions are off-topic here. Do not ask questions about how to write code in C. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.

Filter by
Sorted by
Tagged with
0 votes
0 answers
10 views

Help regarding evaluating the expression? [closed]

int main(int argc, char const *argv[]) { int a = 1; int b = (++a) + (a++); cout << b; return 0; } My approach : ...
user avatar
0 votes
0 answers
10 views

Strides of array and their relation to temporal and spacial locality

I'm really having trouble understanding strides of arrays, and how they relate to temporal and spatial locality in general. I was hoping I could get some help understanding it here. I have the ...
user avatar
1 vote
0 answers
19 views

How to decide row / column strides for a loop over a matrix get these cache hit rates?

Given CPU with: L1 cache: 4-ways, block size = 32 bytes , cache size = 64KB , LRU (Cache replacement policy). L2 cache: 2-ways, block size = 32 bytes , cache size = 512KB , LRU (Cache replacement ...
user avatar
1 vote
2 answers
55 views

Questions about compilers and machine code

When it is said that machine code is specific to a machine, is it specific to an architecture, or is it specific to a machine? Do two identical processors require different machine code? My guess is ...
user avatar
1 vote
3 answers
225 views

Why is C still the fastest? Critique my take

A friend and I were surprised that C still has near-best performance among languages. I thought about why this is, and I wrote up a few paragraphs. I wonder if the friendly folks on CS stack could ...
user avatar
  • 115
0 votes
1 answer
103 views

Difference between bits and bytes?

What are bits and bytes? How do they differ? What role do these notions play in the computer science world? Why do talk about 8 bits = 1 byte = 256 states or different patterns? What's the rationale ...
user avatar
0 votes
0 answers
24 views

What is bit (or binary digit)?

So, if I were to represent 23 in binary, what are bits here? Are 0 and 1 called bits? What they mean when they say I have five bits of information?
user avatar
-1 votes
1 answer
121 views

What does zsh: suspended ./a.out mean? [closed]

I was writing a program to count lines from an input text stream. This is the program. It compiles perfectly but when I execute ./a.out to get the output my ...
user avatar
2 votes
2 answers
631 views

What are pointers in low-level language like C

I was trying to understand pointers by watching YouTube videos. However, I could not understand How do they work? Why do we use them? When do we use them?
user avatar
1 vote
1 answer
151 views

C: iterate over a unicode (utf-8/utf-16) string, conditionally modify individual characters, and store it as new string [closed]

C's char array can hold an ASCII string, such that a user can query individual characters by indexing the char array, modify them or do what ever they want to, its pretty straight forward. I have ...
user avatar
2 votes
4 answers
357 views

Why was the fast inverse square root algorithm so ingenious?

In 2005 ID software open source the game Quake 3 Arena. When they did it was discovered was an algorithm that was so ingenious and all it did was calculate the inverse of a square root. The easy way ...
user avatar
1 vote
2 answers
903 views

How C++ and alike maps are actually stored in memory?

I admit I didn't know much before what a Map is living with just the terminology Hash Tables, even when I first Google it I found this https://www.mathworks.com/help/matlab/matlab_prog/overview-of-the-...
user avatar
  • 140
-2 votes
1 answer
243 views

Must a partial halt decider be a pure function of its inputs?

Must a partial halt decider be a pure function of its inputs? A partial halt decider correctly decides the halt status of some of its inputs. I am trying to write C code that would be acceptable to ...
user avatar
  • 113
-1 votes
1 answer
159 views

Checksum Algorithm that produces correct 16-bit checksum value for any given input

I need a checksum algorithm that produces the correct 16-bit checksum value for a given input. It's a packet recording from serial communication that I would like to reverse engineer. I have two data ...
user avatar
2 votes
3 answers
63 views

Why doesn't the compiler typecast the pointer and remove the error? (C++ Programming)

int *numPtr; double num; numPtr = &num; This code shows an error as pointer points to data of different datatype. But why does it show the error? Why doesn't ...
user avatar
  • 21
0 votes
1 answer
64 views

Pointers and Dereference Operator

*a = *b In C, the above expression is always interpreted as the assignment of the value at the address contained in b to the value at an address in a. But, according to the precedence of operators and ...
user avatar
6 votes
1 answer
922 views

How are extremely large integers stored and implemented in programming languages?

We have data types like int and long etc. which can store just a few bytes of integers. But when we are implementing ...
user avatar
2 votes
0 answers
493 views

What assigns the physical addresses to variables?

Earlier I was having a technical test when I stumbled across this question: I know that probably in modern systems, the OS and the MMU is responsible for that. But the test was focused on Embedded ...
user avatar
-6 votes
1 answer
305 views

Halting problem undecidability and infinitely nested simulation

Halting problem: In computability theory, the halting problem is the problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running, ...
user avatar
  • 113
-7 votes
1 answer
439 views

Are the halting problem proofs refuted by software engineering?

Are the halting problem proofs refuted by software engineering ? This is an explanation of a possible new insight into the halting problem provided in the language of software engineering. Technical ...
user avatar
  • 113
0 votes
1 answer
177 views

Find offset and page number given paged virtual memory address

I ran into this question in class: Assume a machine that is 64-bit and has 8GB memory. They use a paged virtual memory where the page size is 4KB. You run the following program: ...
user avatar
  • 103
0 votes
1 answer
69 views

Combinations (repetition not allowed & order not important)

How to compute a table of numbers (all possibilities), where repetition is not allowed and order is not important. Example: I have a set of prime numbers. In this example I have four: {3,5,7,11}, but ...
user avatar
3 votes
1 answer
69 views

Why is the address-of operator in C/C++ represented with the "&" symbol?

I've started learning C++, and I know a little bit of C. Something that always struck me as somewhat off was that the address-of operator is represented with the seemingly random ampersand (&) ...
user avatar
  • 31
0 votes
0 answers
34 views

How to help compiler do pipelining?

I don't mean compiler flags for pipelining. I would like to program in a way that helps the compiler do optimizations using pipelining. I mean I want to order instructions in C in such a way that GCC (...
user avatar
2 votes
2 answers
343 views

How are kernels (and operating systems in general) written in C?

I'm trying to understand how you set about writing an OS in something like C. I've always used C to write applications - using commands like malloc and ...
user avatar
0 votes
0 answers
131 views

matrix product openMP code in C runs slower in parallel than series

If I start with 4 threads when I run my code and increase thread number each time I run it, my run time decreases as you would expect. However, my run time for 1 thread is significantly smaller than ...
user avatar
  • 1
1 vote
1 answer
32 views

What is the correct algorithm to see whether N points lie on the same side of a line?

What I tried first was to find the equation of the line and then compare its y-intercepts with the y-intercepts of each point. I just need the proper approach to this algorithm.
user avatar
  • 115
-1 votes
1 answer
37 views

Find the most frequent alphabet appearing in the given string. In case letter with same frequency, choose the one which comes first alphabetically

This is the desired result which I want:
user avatar
  • 115
2 votes
1 answer
43 views

printf("%d",~5); prints out -6 why is that?

I was reading the book "Computer systems: A programmer's perspective" and saw that the operator, "~", is a NOT operator. When I use it to NOT positive integers, it returns the ...
user avatar
-1 votes
1 answer
50 views

doubts on cin and scanf [closed]

i spent literally 5hrs trying to figure out, why the value of n is 1 for my second test case ( which begins at line 12 ) , but i am unable to, could you help me with that? ...
user avatar
0 votes
1 answer
200 views

How to Sort 2D array with out 1D array

Hello I am a new Computer Science student Ok, so I am trying to sort the 2D array I know you can actually sort a 2D array by copying it into a 1D array sort it using any Algorithm, and then place ...
user avatar
0 votes
0 answers
42 views

whats the use of Elf64_Symbol struct?

below is two pictures in regards to Executable and Linkable Format(ELF): My questions is: we know that Relocatable Object Files in ELF format are binary code(0s and 1s), so is Elf64_Symbol struct ...
user avatar
  • 137
1 vote
2 answers
326 views

Are C standard library functions considered part of C programming language

Do we consider functions like printf part of C language even if it's not a keyword in it.
user avatar
1 vote
0 answers
29 views

Race Condition in Mesa Monitor

...
user avatar
  • 111
2 votes
4 answers
111 views

How do compilers assure stability?

Suppose you need a c compiler. It would be preferable to write that compiler in a c-like language, given the complexity of a compiler of that degree. At best, the c compiler would be written in c, but ...
user avatar
9 votes
7 answers
5k views

Checking equality of integers: O(1) in C but O(log n) in Python 3?

Consider these equivalent functions in C and Python 3. Most devs would immediately claim both are $O(1)$. def is_equal(a: int, b: int) -> bool: return a == b <...
user avatar
2 votes
1 answer
693 views

What are the known ambiguities in C language grammar?

I have found this reference for the C syntax Backus-Naur Form (BNF). I was wondering if there are any other ambiguities in this grammar other than the infamous "dangling else"? Also how we ...
user avatar
  • 191
0 votes
2 answers
98 views

Understanding memory leaks in C/C++ [closed]

I was looking at an example here: https://blog.parasoft.com/finding-memory-leaks-in-c ...
user avatar
  • 167
0 votes
0 answers
45 views

How do I compare these ranges of numbers efficiently?

I'm looking for an efficient way of testing eights. What happens is I need to check if a value is eights and discard it. The numbers I need to check for are: ...
user avatar
  • 101
0 votes
2 answers
30 views

Error handling in a size_t hashfunction

For school I have a big assignment on hashtables etc. One of the functions is a size_t function where we calculate the hash value. (Keep in mind the structure of every function is given so we are not ...
user avatar
  • 1
0 votes
0 answers
29 views

Protecting a specific sized message with some limitations

So I make a research on my own. I have a device it allows a 64bit message. I wanted to secure it but I 64bits arent just enough to hash it and encrypt it. Is there really any good Hash function out ...
user avatar
0 votes
2 answers
56 views

When does kernel accessing virtual memory cause problems

I'm working with the CPU Pintos and have a question that is: In which situations can the kernel accessing the data in virtual memory via a pointer lead to problems? And how do you avoid them? I know ...
user avatar
1 vote
2 answers
284 views

Is call stack compile time or runtime detail?

I'm sorry if the question is quite naive, but I don't understand if a call stack is a language implementation detail or it depends on OS? What I'm trying to understand is what decides how to store ...
user avatar
1 vote
1 answer
85 views

does a non-terminated string count as a token in c?

so, I am preparing for an exam which includes lexical analysis from compiler design. I was wondering what is the number of tokens in the following code- ...
user avatar
3 votes
2 answers
145 views

What does the following algorithm approximate? (Assume m>1,ϵ>0)

x = m; y = 1; While (x-y > ϵ) { x = (x+y)/2; y = m/x; } print(x); The answer is m½, its the Babylonian algorithm for square roots. I understand the ...
user avatar
  • 83
1 vote
1 answer
256 views

Global variables and frame stack [closed]

The below program will read a positive integer from keyboard and print the binary equivalent. This program is using only one variable. If global variables are not stored in frame stack, how this is ...
user avatar
1 vote
1 answer
103 views

How does dynamic memory-allocation exactly work?

I have wondered about ordinary code. Assume we are running this code on any modern System like Unix/Linux/Mac/Windows. This code is C, but it should work with every language which is close to the ...
user avatar
  • 287
1 vote
0 answers
45 views

Design considerations of datatypes in early programming languages like C

Although type theory originated (e.g. already discussed by Russell in 1910s) much earlier than programming languages, I have this feeling that languages such as C considered type-checking from a very ...
user avatar
  • 259
1 vote
2 answers
504 views

How does casting really work for primitive data types? [closed]

I have written the following C code which purpose it is to flip an unsigned number in binary representation and give back an unsigned number: ...
user avatar
  • 287
1 vote
1 answer
129 views

Sizeof function definition in a system

Why sizeof(int) and sizeof(int *) takes different value in a system? I mean generally size of integer is 4 B, but size of integer pointer is 8 B. But why they cannot take same value, although their ...
user avatar
  • 53