

The answer: all strings in C are terminated by a NUL byte (a char storing numeric value 0), also known as \0. This raises the question: couldn’t you just keep incrementing this pointer? How would you know where the end of the string is? And if you increment the value of the pointer by 1 (going to the next box) and dereference that value, you would get the next character of the string.

Since store is defined as a char pointer, store will point to a byte of memory that stores a character.

char * store = “hello” for ( int i = 0 * (store + i ) != '\0' i ++ ) Instead of having a datatype explicitly called “string”, in C, you can think of char pointers (i.e., char* ) as strings. That’s because strings in memory are just a sequence of one bytes, each represented as a char (a 1-byte value). Īs you will notice, there isn’t an explicit data type called “string” in C. And that address refers to the first byte of a 4-byte sequence of memory that stores an int. On a 64-bit architecture (which most computers today use), the pointer occupies 8 bytes in memory, which store the address it points. For instance, int* is a pointer to an integer.

Pointers are memory locations that store addresses (i.e., they “point” at whatever is at that address!).
MAKEFILE FOR C PROGRAM IN LINUX CODE
You will be writing two functions in the file reverse.c and you will test your implementation with the code found in test_reverse.c. In this part of the lab, you will be writing a program that will reverse an array of strings (or, as they are known in C, char pointers). You will be writing your code in this file.Ĭontains the test suite in which your implementation will be tested. More information about this file is in the file itself. Contains declarations for the functions you should be implementing. Assignment Part I: C Programming SetupĪfter you set up the lab, you should find within the lab1 folder a couple of files: File Run git push to save your work back to your personal repository. If you have any “conflicts” from Lab 0 (although this is unlikely), resolve them before continuing further. This will merge our Lab 1 stencil code with your previous work. If this reports an error, run: $ git remote add handout Start with the cs300-s21-labs-YOURNAME repository you used for Lab 0.įirst, ensure that your repository has a handout remote. If you are looking for a detailed tutorial on C, check out the links on our C primer. The main features of the C language include low-level access to memory, a simple set of keywords, and clean style, these features make C suitable and widely-used for system programming. Don’t be afraid to look up questions on Stack Overflow and Linux Man Pages (which provide great documentation on C library functions), and if that doesn’t help, ask on Piazza! Why C?Ĭheck out this article for more on why C programming is awesome! Here are some of the article’s highlights: C is an imperative programming language that was mainly developed as a systems programming language to write operating systems. If you take away anything from this course, hopefully, it’s that Computer Systems are not magic and that much of it actually makes a lot of sense. After this lab, you will also be more familiar with pointers and why C and C++ use them. The purpose of this lab is to give you some experience with writing and understanding the syntax of C programs and apply the tools used to compile and run them. Completed the Diversity Survey – Your grades for Lab 0 and Lab 1 will depend on whether you’ve submitted this (though all questions are optional). Completed Lab 0 – This will ensure that your VM and grading server account are set up properly.Ģ. Before attempting this lab, please make sure that you have:ġ.
