# 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.

103 questions
Filter by
Sorted by
Tagged with
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 ...
• 109
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 ...
• 121
68 views

...
1 vote
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 ...
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 ?...
1 vote
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 ...
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 ...
• 207
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 ...
• 207
1 vote
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: ...
• 208
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 ...
1 vote
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 ...
• 141
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 ...
• 101
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 ...
1 vote
34 views

### Shell algorithm knuth sequence time complexity analysis

Given this shell sort algorithm implementation: ...
• 21
47 views

### Help with time complexity of a given code

Given the following code: ...
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 ...
• 183
1 vote
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, ...
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 ...
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 ...
• 11
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 ...
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 ...
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 ...
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 ...
1 vote
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 ...
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: ...
1 vote
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 ...
1 vote
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 ...
1 vote
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 ...
• 115
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 ...
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?
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 ...
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?
• 51
1 vote
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 ...
• 111
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 ...
• 145
1 vote
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-...
• 138
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 ...
• 85
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 ...
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 ...
• 21
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 ...
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 ...
• 139
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 ...
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 ...
• 85
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 ...
• 85
1 vote
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: ...
• 113
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 ...
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 (&) ...
• 31
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 (...
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 ...