Hey, the C language--there's no stupid problem here (i)

Source: Internet
Author: User
Tags arithmetic stdin


Q: What do you mean by card_name[0]?
A: It is the first character entered by the user. If the user enters 10, then card_name[0] will be 1.
Q: Do I always have to write comments with/* and/*?
A: If your compiler supports the C99 standard, you can start commenting with//. The compiler will treat the remainder of this line as an injection.
Q: How do I know which criteria my compiler supports?
A: You can view the compiler's documentation. For GCC, ansi,c,c99 and C11 all of the three standards it supports.
Q: Why do I have to add./? In front of the program when I run the program on Linux and Mac.
A: Because in a UNIX-like operating system, the running program must specify the directory where the program resides, unless the program's directory is already listed in the PATH environment variable.
Q: Why do characters start numbering from 0? Why not 1?
A: The index value of a character is an offset value: it represents the number of characters between the character that is currently being referenced and the first character in the array.
Q: Why do you do this?
A: The computer stores characters in contiguous bytes in memory and uses the index to calculate the position of characters in memory. If the computer knows C[0] is located in the memory 1 000 No. 000 unit, then you can quickly calculate the c[96] in the 1 000 000+96 unit.
Q: Why should I set up Sentinel characters? Doesn't the computer know the length of the string?
A: I don't usually know. The length of the record array is not the strength of the C language, and the string is actually a group of numbers.
Q: How long does the C language know about arrays?
A: Yes, although the compiler has the ability to calculate the length of the array by parsing the code, in general, C Voice expects you to record the length of the arrays.
Q: Is there a difference between single and double quotes?
A: There are differences, single quotes are usually used to represent a single character, and double quotation marks are often used to represent strings.
Q: I should define a string in double quotation marks ("). or define a string as an explicit character array?
A: You should usually use double quotation marks to define a string. A string defined in double quotes is called a string literal (string literal), which is easier to enter than a character array.
Q: Is there a difference between string literals and character arrays?
Answer: There is only one difference: string literals are constants.
Q: What does that mean?
A: This means that once these characters have been created, they cannot be modified.
Q: What happens if I change it?
A: Depending on the compiler, GCC usually displays bus errors.
Q: Bus error? What is that thing?
A: The C language takes a different approach to storing string literals in memory. A bus error means that the program cannot update that memory space.
Q: Why can't I write a | and &?
Answer: No, not at all. & and | Operators always calculate two conditions, while && and | | A second condition can be skipped.
Q: What else do you want | and &?
A: Evaluating logical expressions is only one of their uses, and they can also perform boolean operations on one of the numbers.
Q: What does that mean?
A: 6 & 4 equals 4, because when you pair (binary 110) and 4 (binary number 100) for each bits Boolean, you get 4 (binary number 100).
Q: Why should I replace the IF with a switch statement?
A: It is easier to use a switch statement when you need to check the same variable multiple times.
Q: What are the benefits of using a switch statement?
A: There are several benefits. First, make the code clearer, a piece of code to deal with a variable structure, structure at a glance, instead, a series of if statements are not so clear; second, you can use the drop logic to reuse code between different branches.
Q: Can the switch statement only check variables? Can it check the values?
A: Yes, the switch statement only checks that two values are equal.
Q: Can I check the string in the switch statement?
A: You cannot use a switch statement to check a string or any form of an array, and the switch statement can only check values.
Q: If I create a void function, does that mean it must not have a return statement?
A: You can still include a return statement, but the compiler is likely to produce a warning message. And it doesn't make sense to include the return statement in the void function.
Q: Really? Why doesn't it make sense?
Answer: Because if you try to read the value of the void function, the compiler will error.
Q: Why does the C voice need to be compiled? Some other voices don't need to be compiled, like JavaScript, do they?
A: In order for the code to execute faster, C voice needs to be compiled. Although there are write voices that are not compiled languages, some of them, to JavaScript and Python, often use some compilation techniques behind the scenes to improve speed.
Q. C + + is another version of C voice?
A: No, although C + + is designed to extend C, it seems far more than that, and the C + + and objective-c that people originally created are all for C-speech object-oriented programs.
Q: What is Object-oriented? Do we learn in this book?
A: Object-oriented is a technology that combats software complexity, and we don't do a specific study in this book.
Q: Why does the C voice look like Javascript,java and C # language?
A: The C language syntax is very concise and therefore affects many other languages.
Q: What does the three letters of GCC mean?
A: GNU compiler set (GNU Compiler Collection)
Q: Why is a "suit"? Is it more than a C language?
A: The GNU compiler Suite can be used to compile many languages, while the C language may be the language that people use most when they should be gcc.
Q: Can I create a never-ending loop?
A: Yes, if the value of the loop condition is 1, the loop will run indefinitely.
Q: Is it a good idea to create a never-ending loop?
A: Sometimes, in some programs, such as Web servers, an infinite loop is used (a never-ending loop), and the program does something repeatedly to know that people stop it. But most programmers use loops to get them to stop at some point.
Q: I have printed the variable's unit number on my machine, but it is not 4 100 000. What's wrong?
A: You did not do wrong, in different machines, the program used to save the variable memory unit number is different.
Q: Why are local variables saved in the stack, while global variables are stored elsewhere?
A: The use of local variables differs from global variables. You can always get a global variable, but if you write a function that calls yourself, you get a lot of instances of the same local variable.
Q: What other areas of memory are used for?
A: You'll see how they work in subsequent chapters of this book.
Q: Is the pointer a real address unit, or is it a form of reference?
A: They are real numbered addresses in process memory.
Q: Why is the memory process?
A: The computer assigns a simple version of the memory to each process and looks like a long string of bytes.
Q: But memory is not so?
A: The actual memory is much more complex, but the details are hidden from the process so that the operating system can move the process in the memory, or release it and reload it to another location.
Q: Is memory more than a long list of bytes?
A: The structure of the physical memory is very complex, and the computer usually maps the memory address into different storage (memory bank) of the storage chip.
Q: Do I need to understand how it is mapped?
A: For most programs, you don't need to care about the details of the machine's memory.
Q: Why do I have to print pointers with%p format strings?
A: You don't have to use%p, you can use%li on most modern computers, but the compiler might give you a warning.
Q: Why does%p display the memory address in hexadecimal?
A: Engineers typically represent memory addresses in hexadecimal.
Q: If we call the content of the Read memory unit "dereference", should the pointer be called "reference"?
A: People sometimes call the pointer "reference" because it refers to an address unit in memory. But C + + programmers typically use "references" to represent a slightly different concept in C + +.
Q: Great, C + +, will we learn?
A: Don't think, this book only teaches C language
Q: Is sizeof a function?
Answer: No, it is an operator.
Q: What's the difference?
A: The compiler compiles the operator into a sequence of instructions, and when the program calls the function, it jumps into a separate piece of code to execute.
Q: So the program calculates sizeof during compilation?
A: Yes, the compiler can determine the size of the storage space at compile time.
Q: Why are pointer variables different sizes on different computers?
A: In a 32-bit operating system, the memory address is stored as a 32-digit number, so it is called a 32-bit operating system. 32-bit ==4 bytes, so the 64-bit operating system uses 8 bytes to save the address.
Q: If I create a pointer variable, is it in memory?
A: Yes, the pointer variable is just a variable that holds the number.
Q: Can I find the address of the pointer variable?
A: You can use the & operator to find its address.
Q: Can I convert my pointer to a normal number?
Answer: In most operating systems, you can do this. The C compiler typically sets the long data type to be the same length as the memory address. If you want to save the pointer p in a long variable A, you can enter A=long (p).
Q: Is it in most operating systems? So not all of them?
Answer: Not all.
Q: Do I really need to understand pointer arithmetic operations?
A: Some programmers don't use pointer arithmetic, because it's easy to make mistakes, but you can use it to work with array data efficiently.
Q: Can the pointer do subtraction?
Answer: Yes, but be careful not to let the pointer cross the array's starting point.
Q: When does the C language adjust pointer arithmetic operations?
A: When the compiler builds the executable, the compiler multiplies the variables by the size of the variable, depending on the type of the variable, or by the increment or decrement of the pointer.
Q: And then what?
A: If the compiler sees you adding 2 to a pointer to an int array, it will multiply by 2 by 4 (int length) and then add 8 to the address.
Q: Does the C language use the sizeof operator when adjusting pointer arithmetic operations?
A: In essence, the result of the sizeof operator is also determined at compile time, and the same length will be used for various data types, sizeof and pointer arithmetic operations.
Q: Can the pointer be multiplied?
Answer: No.
Q: Why do we define arrays as tracks[][80] instead of tracks[5][80]?
A: You can also define this, but the compiler knows that the list has 5 items, so you can omit 5 to write [].
Q: So why not just write tracks[][]?
A: The name of each song is not the same length, in order to drop the longest song name, you need to let the compiler allocate enough space.
Q: Which means that each string in the tracks array has 80 characters?
A: The program assigns 80 characters to each string, even if the song name is short.
Q: So the tracks array altogether accounted for 80 * 5 = 400 characters?
Answer: Yes.
Q: What happens if I forget to string.h such a header file?
A: For some header files, the compiler will give you a warning, but it will still contain them, but for others, the compiler will directly prompt for compilation errors.
Q: Why do we define the tracks array outside of the function?
A: We put tracks in the global domain, and global variables can be used in all functions.
Q: Since we have created two functions, which one will the computer run first?
A: The program always runs the main () function first.
Q: Why do I have to put Find_track () before main ()?
A: Before invoking a function, the compiler needs to know two things, what parameters the function receives, and what the function's return value type is.
Q: What happens if I put main () in front?
A: You will get a few warnings.
Q: Since there are stdout and stderr, naturally there is stdin it?
A: Yes, as you expected, it represents the standard input.
Q: Can I print stdin?
Answer: No
Q: Can I read data from stdin?
A: Well, you can use FSCANF () to read, its usage and scanf () very much like, the difference is that you can automatically fscanf () from which stream to read the data.
Q: That is to say fscanf (stdin,...) and scanf () equivalent?
A: Yes, it's exactly the same. In the final analysis, scanf () is fscanf (stdin,...) Implemented.
Q: Can I redirect standard errors?
A: Yes, you can use the > redirect standard output,2> redirect standard error.
Q: So I'm going to write Geo2json > errors,txt?
Answer: Yes
Q: Why do gadgets use standard input and standard output?
A: With them, you can easily use a pipe to link the gadget.
Q: Why do they have to be chained together?
A: Gadgets can only solve a small technical problem, such as changing the format of the data, rather than solving the whole problem. They can only be combined to solve big problems.
Q: What exactly is a pipeline?
A: Different operating systems implement pipelines in different ways, may use memory, may also use temporary files. We just need to know that it receives the data from one end and sends the data on the other end.
Q: If two programs are connected by pipelines, does the second program have to wait for the first program to finish before it starts running?
A: Not required, two programs can be run at the same time, the first program to send out data, the second program can be processed immediately.
Q: Why do gadgets use text?
A: Text is a development format, programmers can use a text editor to see the output of the gadget, and understand the content inside, in contrast, the binary format is more difficult to understand.
Q: Can I connect multiple programs with a pipe?
A: Yes, just add a 1 in front of each program, and a chain of connected processes is called pipelining (pipeline).
Q: When I use pipelines to connect multiple processes,,< and > redirect which process's standard input, which process's standard output?
Answer:< will send the file content to the standard input of the first process in the pipeline, > will capture the standard output of the last process in the pipeline.
Q: When I run the Bermuda and Geo2json programs on the command line, are the parentheses outside necessary?
A: Yes, the parentheses guarantee that the data file is read by the standard input of the Bermuda program.
Q: How many data streams can I have?
Answer: It depends on the operating system. Typically, a process can have up to 256 streams of data, but keep in mind that the number of data flows is limited and should be closed when you're done.
Q: Why does file have to be capitalized?
A: Long story, the earliest file is defined by a macro, and the name of the macro is usually capitalized.
Q: Can i merge two options? For example, replace-D now-t with-td now.
A: Yes, the getopt () function will handle them in its sole discretion.
Q: Can I change the order of the options?
A: Yes, because we use the loop read option, so-D now-t,-t-d now,-TD now are all the same.
Q: In other words, as long as the program sees a prefix-value on the command line, it treats it as an option?
A: Yes, if it must appear before the command line arguments.
Q: What if I want to use negative numbers on command line parameters? Like Set_temperature-c--Will the program take 4 as an option?
A: To avoid ambiguity, you can use--separate parameters and options, such as Set_teperature-c---4. Getopt () sees-stops the read option, and the program reads the subsequent contents as normal command-line arguments.
Q: Why are the data type sizes different for different operating systems? It's not as clear as it should be?
A: In order to accommodate the hardware, C language uses different data type sizes on different operating systems and processors.
Q: What do you say?
A: The birth of C language is still the world of 8-bit machine, but now most of the computers are 32-bit and 64-bit, because C language does not specify the size of the data type, so as to advance with the times. Even if the new computer is processed, the C language can adapt well.
Q: 8-bit, 64-bit what exactly does that mean?
A: Technically speaking, the number of digits of a computer has many meanings, it can represent the length of the CPU instruction, or it can represent the size of the CPU to read the data from memory at one time. In fact, the number of digits is the numeric length that the computer can handle.
Q: What does this have to do with the size of int, double?
A: If a computer can handle 32-bit numeric values, the size of the base data type (for example, int) is set to 32 bits.
Q: I know how integers like int work, but how is a float or double stored? How does a computer represent a number with a decimal point?
A: Long story, most computers use the standards published by the IEEE.
Q: Do I need to understand how floating point numbers work?
A: No, most programmers use float and double without paying attention to their details.

Hey, the C language--there's no stupid problem here (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.