Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the interview questions and answers for C language programming?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the interview questions and answers for C language programming". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the interview questions and answers for C language programming?"

1. What is the difference between the declaration and definition of a variable / function

Answer: the declaration of a variable / function only declares that the variable / function exists somewhere in the program, but no memory is allocated to it. But the declaration of variables / functions plays an important role. This is the type of variable / function. Therefore, when you declare a variable, the program knows the data type of the variable. In the case of declaring a function, the program knows what the parameters of the function are, their data types, the order of the parameters, and the return type of the function. This is the statement. With regard to definition, when we define a variable / function, in addition to the role of the declaration, it allocates memory for the variable / function. Therefore, we can think of the definition as a superset of the declaration. (or declared as a subset of the definition).

2. What are the different storage class specifiers in C?

Answer: auto, register, static, extern

3. What is the range of variables? What is the scope of variables in C?

Answer: the scope of a variable is part of the program and can be accessed directly. In C, all identifiers are within the lexical (or static) range.

4. How do you print "Hello World" without a semicolon?

# include

Int main (void)

{

If (printf ("Hello World")) {

}

}

5. When should I use pointers in C programs?

Answer:

1. Get the address of the variable

two。 In order to implement reference passing in C: pointers allow different functions to share and modify their local variables.

3. Through large structures to avoid copying the structure completely.

4. Implement "link" data structures, such as link lists and binary trees.

6. What is a NULL pointer?

Answer: NULL is used to indicate that the pointer does not point to a valid location. Ideally, if the value of the pointer is not known at the time of declaration, the pointer should be initialized to NULL. In addition, when the middle of the memory program that it points to is released, we should make the pointer NULL.

7. What is a dangling pointer?

Answer: a dangling pointer is a pointer that does not point to a valid memory location. When you delete or release an object, if you do not change the value of the pointer, a dangling pointer appears, so the pointer still points to the storage location of the freed memory. The following is an example.

/ / example 1

Int* ptr = (int*) malloc (sizeof (int))

.. free (ptr)

/ / ptr is a dangling pointer, the following operation is invalid

* ptr = 10

/ / example 2

Int* ptr = NULL {int x = 10; ptr = & x;}

/ / x is out of range, and the memory allocated to x is now available

/ / so ptr is now a dangling pointer

8. What is a memory leak? Why should you avoid using it

Answer: memory leaks occur when programmers create memory in the heap and forget to delete it. Memory leaks are a particularly serious problem for programs such as daemons and servers, which by definition never terminate.

9. What is a local static variable? What are they for?

Answer: a local static variable is a variable whose lifetime does not end with the function call that declares it. It extends the life of the whole program. All calls to this function share the same copy of the local static variable. Static variables can be used to calculate the number of times a function is called. In addition, the default value for static variables is 0. For example, the following program outputs "0 1"

# include

Void fun ()

{

/ / the default value of static variable is 0

Static int x

Printf ("d", x)

X = x + 1

}

Int main ()

{

Fun ()

Fun ()

Return 0

}

/ / output: 0 1

10. What is a static function? What are they for?

Answer: in C, functions are global by default. The "static" keyword before the function name makes it static. Unlike global functions in C, access to static functions is limited to the files in which they are declared. Therefore, when we want to restrict access to functions, we make them static. Another reason for making a function static may be that the same function name is reused in other files.

At this point, I believe you have a deeper understanding of the "C language programming interview questions and answers". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report