Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

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
1 answer
40 views

Selection sort on the array $\{5,9,11,10,2\}$

I want to understand how the algorithm of selection sort sorts the given array, $$A[5]=\{5,9,11,10,2\}$$ Step -$1:-$ I compare A[0] with remaining elements of the array and since $A[4]<A[0]$ I swap ...
RAHUL 's user avatar
  • 109
2 votes
4 answers
73 views

Are float pseudo-random number generators always implemented using integer generators underneath

In C it's well known to use simple routine for turning integer rng into float rng. Something like that ...
simd's user avatar
  • 121
2 votes
1 answer
68 views

Calculate the CPI of a program

...
First_1st's user avatar
1 vote
0 answers
123 views

Oldest Operating System still in use today?

Reading through https://en.wikipedia.org/wiki/Timeline_of_operating_systems to decide where to port some library software—network|crypto|archive abstracting—I'm writing in C (C89). DOS is definitely ...
Samuel Marks's user avatar
0 votes
1 answer
71 views

How do you tell whether a binary number is positive or negative?

Consider the figure in Exercise 2. If the current machine code that executes is 0x214bfffd and the values of the registers in the processor are as shown below, what is then the value of the input WD3 ?...
First_1st's user avatar
1 vote
0 answers
40 views

How do i make a 2d array as same as i possibly can with another one?

Say i have an 2d array A of nxn size, int values already given for each item.these values can be the same or different. There's gonna be another nxn array B being input. I can only interchange one row ...
HelpmePlease's user avatar
0 votes
1 answer
40 views

What is the reason or advantage of having special purpose status flags for the result of comparisons? [duplicate]

The C semantics treat the result of a comparison or any true/false operation as just an int ...
CPlus's user avatar
  • 207
0 votes
1 answer
55 views

What is the purpose of padding bits in primitive integer types?

The C standard carves out room for implementations which have padding bits in their integer types. Padding bits affect the size of an integer but not the number of possible values they can contain. I ...
CPlus's user avatar
  • 207
1 vote
2 answers
97 views

Why is `3[arr]` notation of accessing elements in array is not used?

Today, I came across the notation 3[arr] in C++, and I was surprised to find out that it's a valid way to access array elements. For example: ...
tbhaxor's user avatar
  • 208
0 votes
2 answers
59 views

finding wrong elements in a descending sorted array using binary search

i have this question where im given a an array that contains the distance of a traveler from a certain destination at the i-th time of the day. ideally the array should be in descending order but the ...
user1188938's user avatar
1 vote
1 answer
119 views

Requirements to a CPU architecture to actually allow a C compiler to be built for it

I have this rather weird CPU architecture for which currently only an assembler exists. I won't go into too much details about this architecture as it is not publicly available. However, some quirks ...
GNA's user avatar
  • 141
0 votes
0 answers
56 views

I want to get into Operating Systems, where do I start?

I have been doing web/app development for a few years, primarily involving high-level programming and stuff. However, I am interested in jumping into some low-level stuff and genuinely understanding ...
Ryan Wang's user avatar
  • 101
0 votes
1 answer
59 views

How to visualize 1 pixel?

The CS50 course by Edx that I am pursuing has this statement in their Week 4 practice set: A 24-bit BMP file, then, is essentially just a sequence of bits, (almost) every 24 of which happen to ...
Splendid Digital Solutions's user avatar
1 vote
0 answers
34 views

Shell algorithm knuth sequence time complexity analysis

Given this shell sort algorithm implementation: ...
Kim's user avatar
  • 21
0 votes
1 answer
47 views

Help with time complexity of a given code

Given the following code: ...
complexity's user avatar
8 votes
4 answers
5k views

How does the linker know where to look for a function implementation in C++?

I am currently learning about how the compilation and linking works in C++. I think I kinda get how the compiler works, and that for a file to fully compile you don't need to have function ...
artas2357's user avatar
  • 183
1 vote
1 answer
50 views

Upper limit of instructions of a program for a Turing machine that has been converted from a real programming language

Imagine that I have an algorithm written in C that is of, let's say, 10,000 characters in length. Such a program can be simulated on a turing machine (Wikipedia: Anything a real computer can compute, ...
CasseroleBoi's user avatar
5 votes
3 answers
2k views

automatic memory allocation

Global variables are given fixed addresses in main memory by the C compiler, called static memory allocation. Function local variables are created on the stack, this is called automatic memory ...
DanielJackson1's user avatar
0 votes
1 answer
199 views

Does the Posix read() system call for FILE* have an internal buffer in the kernel?

Does the answer depend on the number of bytes requested? If it is forced to keep a buffer due to some unknown device/diver, can it optimize and skip the buffer if it's going to be a disk read? I'm ...
estin's user avatar
  • 11
11 votes
10 answers
6k views

In C, why limit || and && to evaluate to booleans?

In some languages, e.g. Ruby, an expression like: val = call_fn() || DEFAULT_VAL; will set val to the results of call_fn() if ...
fearless_fool's user avatar
0 votes
1 answer
235 views

how to get the high 32-bit of the answer of two 32-bit integer multiple?

Recently, I study the instruction set of riscv32 and face a order as "mulh" which tends to multiply two 32-bits signed integers and store the high 32 value into the register. And here comes ...
Ecthelion's user avatar
0 votes
1 answer
1k views

BNF and EBNF Syntax for while loops in C#

Given the programming language C#, how would I be able to write the BNF and EBNF grammar syntax of its while loop? After trying to search and understand more, I got this as my BNF grammar for while ...
Randomguy's user avatar
0 votes
0 answers
28 views

How to merge both, mutable and immutable worlds?

In the ideal world, systems are designed using immutable data structures. However, when you dive deeper into lower levels of abstractions, you realize that at some point a library written in C is ...
Yulio Granja's user avatar
1 vote
1 answer
237 views

Is it true that everything is a side effect in C?

I'm just a beginner, I've started learning programming, CS, math, and Unix. I know how to code in Pascal and also study C. In the university a professional programmer, who teaches coding, said that ...
George Glebov's user avatar
0 votes
0 answers
41 views

How to calculate how many times a function inside a for loop inside a while loop will be called?

I'm studying for my exams and a came through this exercise but I can't prove the result I found. Given this piece of code: ...
Nikolas P.'s user avatar
1 vote
0 answers
39 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 ...
JobProcessTask's user avatar
1 vote
2 answers
88 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 ...
prss98408's user avatar
1 vote
4 answers
544 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 ...
Eric Auld's user avatar
  • 115
0 votes
1 answer
375 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 ...
Vinay Sharma's user avatar
0 votes
0 answers
54 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?
Vinay Sharma's user avatar
-1 votes
1 answer
371 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 ...
kraanasgard's user avatar
3 votes
2 answers
827 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?
salluc 1's user avatar
1 vote
1 answer
861 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 ...
codepoet's user avatar
  • 111
2 votes
4 answers
1k 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 ...
Neil Meyer's user avatar
1 vote
2 answers
4k 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-...
ShAr's user avatar
  • 138
-4 votes
1 answer
270 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 ...
polcott's user avatar
  • 85
-1 votes
1 answer
600 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 ...
user141929's user avatar
2 votes
3 answers
242 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 ...
Kshitij's user avatar
  • 21
0 votes
1 answer
351 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 ...
Aman Rathore's user avatar
6 votes
1 answer
1k 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 ...
Yuv's user avatar
  • 139
2 votes
0 answers
2k 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 ...
Amr Mohamed's user avatar
-7 votes
2 answers
502 views

Simulating Halt Decider Applied to the Halting Theorem

A key breakthrough is that the author of the best selling book on the theory of computation MIT professor Michael Sipser has agreed that the following verbatim paragraph is correct: If simulating halt ...
polcott's user avatar
  • 85
-9 votes
1 answer
626 views

Are the halting problem proofs refuted by software engineering?

Can D simulated by H terminate normally? The x86utm operating system based on an open source x86 emulator. This system enables one C function to execute another C function in debug step mode. When H ...
polcott's user avatar
  • 85
1 vote
2 answers
506 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: ...
Melanie's user avatar
  • 113
0 votes
1 answer
221 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 ...
Natural Number Guy's user avatar
3 votes
1 answer
176 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 (&) ...
Nat H's user avatar
  • 31
0 votes
0 answers
72 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 (...
Alejandro Arcila's user avatar
2 votes
2 answers
1k 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 ...
MysteriousWaffle's user avatar
0 votes
0 answers
450 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 ...
Robin's user avatar
  • 1
1 vote
1 answer
36 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.
sohamb172's user avatar
  • 115