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
50
votes
14answers
15k views

Is C actually Turing-complete?

I was trying to explain to someone that C is Turing-complete, and realized that I don't actually know if it is, indeed, technically Turing-complete. (C as in the abstract semantics, not as in an ...
28
votes
2answers
4k views

Why is C's void type not analogous to the empty/bottom type?

Wikipedia as well as other sources that I have found list C's void type as a unit type as opposed to an empty type. I find this confusing as it seems to me that <...
14
votes
7answers
28k views

Why do negative array indices make sense?

I have came across a weird experience in C programming. Consider this code: ...
8
votes
7answers
4k 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 <...
7
votes
1answer
1k views

Is the Syntax of C Language completely defined by CFGs?

I think the Question is self sufficient. Is the syntax of C Language completely defined through Context Free Grammars or do we have Language Constructs which may require non-Context Free definitions ...
4
votes
1answer
165 views

Sorting Algorithm with constraints

I am looking for a sorting algorithm to help me in my work. My objective is the following: after receiving an input of this kind: 5 4 1 2 2 3 3 4 4 5 The first ...
4
votes
0answers
213 views

Dennis Ritchie citation for “the C declarator syntax is an experiment that failed”?

I've often heard that the C declarator syntax described as "an experiment that failed." I've seen claims that this sentiment is also shared by its creator Dennis Ritchie. Does anybody have an actual ...
3
votes
3answers
369 views

How to enhance my skills as a programmer [closed]

I want to learn Cryptography and so I am interested to master C-programming. I know the basic concepts of C-programming like how to use an array,pointers etc. I want to develop myself so that I can ...
3
votes
2answers
108 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 ...
2
votes
4answers
88 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 ...
2
votes
2answers
2k views

Handling untrusted string input in printf in C [closed]

I stumbled upon the MSDN Best Practices for Code Review. Under the section “Untrusted Inputs”, I found following which I didn't understand properly. Why is the following considered safe? ...
2
votes
2answers
121 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 ...
2
votes
1answer
822 views

Hash multiple integers directly using FNV-1a

An alternative version of FNV-1a hash spread on the internet, which operates directly on integers instead of bytes. The offset basis and prime are the same used in the original version, which operates ...
2
votes
1answer
46 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 (&) ...
2
votes
1answer
32 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 ...
2
votes
1answer
412 views

In a kernel, what are “global constructors”?

I am a beginner developing kernels (though I have developed several Hello World programs in C and C++). I frequently see reference being made to global constructors (e.g., osdev https://wiki.osdev.org/...
2
votes
1answer
185 views

What is this question asking for?-->Test this code, find an error in the program and “construct an instance to demonstrate the error” (in C) [closed]

I am learning the basics of the language C, and so far we have covered up to loops. This question is related to my assignment. The problem is I do not understand what the question is asking. I know ...
2
votes
1answer
387 views

Doubt regarding address calculation in two-dimensional arrays

I am reading about the address calculation formulas for one and two-dimensional arrays. I have two related doubts concerning it. In one of the problems, we are asked to calculate the ...
2
votes
1answer
86 views
1
vote
2answers
188 views

use of C library in operating systems [closed]

I wonder, how is that operating systems make use of libraries as stdio.h if they themselves are the services? I am right? Is the operating system that interacts with the hardware to operations of I/O? ...
1
vote
1answer
53 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- ...
1
vote
2answers
60 views

Are Kernel Codes (which are written in C) compiled during boot time?

I have a confusion regarding how the Kernel is loaded during the boot time. The intuition I have is like following: During installation of an OS, the compiled Code of the Kernel (depending on the ...
1
vote
2answers
148 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 ...
1
vote
2answers
487 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: ...
1
vote
1answer
255 views

Complete the following table by specifying the scope of each declaration

I'm having a hard time understanding this question. Can each declaration have more than one scope or can a declaration have more than one scope? If it's the later it would be: Declaration ...
1
vote
1answer
268 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 ...
1
vote
2answers
2k views

Since physical memory is the RAM where is logical memory stored on the computer?

Since logical memory maps to the RAM (physical memory) it has be stored somewhere right and it will obviously take large bunch of memory of itself. Where is it stored?
1
vote
1answer
28 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.
1
vote
1answer
154 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 ...
1
vote
1answer
89 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 ...
1
vote
1answer
102 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 ...
1
vote
0answers
25 views
1
vote
0answers
41 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 ...
1
vote
0answers
70 views

Why the name static and dynamic in static and dynamic scoping

I am wondering, from where static and dynamic scoping got their names. After understanding the concept of static and dynamic scoping in C, what I assume is that whenever we failed to find out the ...
1
vote
0answers
960 views

trying to understand the diagonal check of 8 queen problem

I was solving the 8 queen problem and tried to look through the internet for comparison solutions to see how my solutions compared to others. I found one very small bruteforce solution that confused ...
1
vote
1answer
91 views

Formal specification; Logical formula

* Initial Question * I'm trying to write a logical formula consists of three Boolean variable C1, C2, C3. My program takes graph as input and checks properties about them. C1 represents presence of ...
1
vote
0answers
33 views

How is a complied program updatable? [closed]

We all know in the case of web sites, to make update just means opening the code, editing it and saving it. And to view the changes we just have to refresh the browser. But what about in the case of ...
0
votes
2answers
106 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.
0
votes
3answers
1k views

What is standardization in computer science?

I was reading about the differences standards and specifications for C. I understood that programming languages are usually stadardized and I learnt that there are different approches to ...
0
votes
2answers
60 views

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

I was looking at an example here: https://blog.parasoft.com/finding-memory-leaks-in-c ...
0
votes
2answers
48 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 ...
0
votes
1answer
224 views

Convert for loop into math sigma notation

Have some code (written in C), need the equivalent notation for mathematics. Is it possible using if-statements and sigma notation for this, and if so, how? ...
0
votes
1answer
78 views

How should I “read” a dereference operator?

For example, when I look at some code like int x = 1; int * y = &x; I can read it like ...
0
votes
2answers
28 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 ...
0
votes
2answers
69 views

Where can I code in C? [closed]

I have an upcoming CS course in uni that uses C and I want to get ahead a little bit this Christmas break but I'm having a hard time figuring out where I can actually code using C. My school uses this ...
0
votes
1answer
732 views

Column Major Order

I have a doubt understanding How a 3-Dimensional array is stored in column Major Order. An array in Row Major order is stored like [plane][row][column] So, for finding address of any element we cross ...
0
votes
1answer
40 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: ...
0
votes
0answers
14 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 (...
0
votes
0answers
26 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 ...
0
votes
0answers
18 views

What is the Memory Bandwidth Usage in a Program Related to?

We can use performance counter tools to check the memory bandwidth usage while a program is running. I want to ask what is this memory bandwidth related to? What parameters are involved in memory ...