日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

C语言试题

發(fā)布時(shí)間:2024/3/24 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C语言试题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

What is the output of the following program?

#include<stdio.h> main() { char *s = "Hello, ""World!";printf("%s", s); }

Output:Hello, World!
這里的兩個(gè)"符號(hào)之間的內(nèi)容被忽略掉了

#include<stdio.h>main() { char s[20] = "Hello\0Hi";printf("%d %d", strlen(s), sizeof(s)); }

Output:5 20
strlen的長(zhǎng)度是‘/0’之前的長(zhǎng)度

Choose the correct order from given below options for the calling function of the code “a = f1(23, 14) * f2(12/4) + f3();”?
運(yùn)算順序取決于實(shí)現(xiàn)

What is a pointer on pointer?
It’s a pointer variable which can hold the address of another pointer variable. It de-refers twice to point to the data held by the designated pointer variable.

int main(int argc, char const *argv[]) {int x = 5, *p = &x, **q = &p;printf("%d\n", **q);printf("%p\n", *q);printf("%p\n", q);return 0; } Output: 5 0x7ffeef348bbc 0x7ffeef348bb0

Therefore ‘x’ can be accessed by **q.

Distinguish between malloc() & calloc() memory allocation.
Both allocates memory from heap area/dynamic memory. By default calloc fills the allocated memory with 0’s.

What is keyword auto for?
By default every local variable of the function is automatic (auto). In the below function both the variables ‘i’ and ‘j’ are automatic variables.

void f() {int i;auto int j; }

NOTE ? A global variable can’t be an automatic variable.

What are the valid places for the keyword break to appear.
Break can appear only with in the looping control and switch statement. The purpose of the break is to bring the control out from the said blocks.

Explain the syntax for for loop.

for(expression-1;expression-2;expression-3) {//set of statements }

When control reaches for expression-1 is executed first. Then following expression-2, and if expression-2 evaluates to non-zero ‘set of statements’ and expression-3 is executed, follows expression-2.

What is difference between including the header file with-in angular braces < > and double quotes “ “
If a header file is included with in < > then the compiler searches for the particular header file only with in the built in include path. If a header file is included with in “ “, then the compiler searches for the particular header file first in the current working directory, if not found then in the built in include path.

How a negative integer is stored.
Get the two’s compliment of the same positive integer. Eg: 1011 (-5)

Step-1 ? One’s compliment of 5 : ~0101->1010

Step-2 ? Add 1 to above, giving 1011, which is -5

What is a static variable?
A static local variables retains its value between the function call and the default value is 0. The following function will print 1 2 3 if called thrice.

void f() { static int i; ++i; printf(“%d “,i); }

If a global variable is static then its visibility is limited to the same source code.

What is a NULL pointer?
A pointer pointing to nothing is called so. Eg: char *p=NULL;

What is the purpose of extern storage specifier?
Used to resolve the scope of global symbol.

main() {extern int i;Printf(“%d”,i); }int i = 20;

Explain the purpose of the function sprintf().
Prints the formatted output onto the character array.

What is the meaning of base address of the array?
The starting address of the array is called as the base address of the array.

When should we use the register storage specifier?
If a variable is used most frequently then it should be declared using register storage specifier, then possibly the compiler gives CPU register for its storage to speed up the look up of the variable.

S++ or S = S+1, which can be recommended to increment the value by 1 and why?
S++, as it is single machine instruction (INC) internally.

What is a dangling pointer?
A pointer initially holding valid address, but later the held address is released or freed. Then such a pointer is called as dangling pointer.

What is the purpose of the keyword typedef?
It is used to alias the existing type. Also used to simplify the complex declaration of the type.

What is lvalue and rvalue?
The expression appearing on right side of the assignment operator is called as rvalue. Rvalue is assigned to lvalue, which appears on left side of the assignment operator. The lvalue should designate to a variable not a constant.

What is the difference between actual and formal parameters?
The parameters sent to the function at calling end are called as actual parameters while at the receiving of the function definition called as formal parameters.

Can a program be compiled without main() function?
Yes, it can be but cannot be executed, as the execution requires main() function definition.

What is the advantage of declaring void pointers?
When we do not know what type of the memory address the pointer variable is going to hold, then we declare a void pointer for such.

Where an automatic variable is stored?
Every local variable by default being an auto variable is stored in stack memory.

What is a nested structure?
A structure containing an element of another structure as its member is referred so.

What is the difference between variable declaration and variable definition?
Declaration associates type to the variable whereas definition gives the value to the variable.

What is a self-referential structure?
A structure containing the same structure pointer variable as its element is called as self-referential structure.

Does a built-in header file contains built-in function definition?
No, the header file only declares function. The definition is in library which is linked by the linker.

Explain modular programming.
Dividing the program in to sub programs (modules/function) to achieve the given task is modular approach. More generic functions definition gives the ability to re-use the functions, such as built-in library functions.

What is a token?
A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.

What is a preprocessor?
Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins.

Explain the use of %i format specifier w.r.t scanf().
Can be used to input integer in all the supported format.

How can you print a \ (backslash) using any of the printf() family of functions.
Escape it using \ (backslash).

Does a break is required by default case in switch statement?
Yes, if it is not appearing as the last case and if we do not want the control to flow to the following case after default if any.

When to user -> (arrow) operator.
If the structure/union variable is a pointer variable, to access structure/union elements the arrow operator is used.

What are bit fields?
We can create integer structure members of differing size apart from non-standard size using bit fields. Such structure size is automatically adjusted with the multiple of integer size of the machine.

What are command line arguments?
The arguments which we pass to the main() function while executing the program are called as command line arguments. The parameters are always strings held in the second argument (below in args) of the function which is array of character pointers. First argument represents the count of arguments (below in count) and updated automatically by operating system.

main( int count, char *args[]) { }

What are the different ways of passing parameters to the functions? Which to use when?
Call by value ? We send only values to the function as parameters. We choose this if we do not want the actual parameters to be modified with formal parameters but just used.

Call by reference ? We send address of the actual parameters instead of values. We choose this if we do want the actual parameters to be modified with formal parameters.

What is the purpose of built-in stricmp() function.
It compares two strings by ignoring the case.

Describe the file opening mode “w+”.
Opens a file both for reading and writing. If a file is not existing it creates one, else if the file is existing it will be over written.

Where the address of operator (&) cannot be used?
It cannot be used on constants.

It cannot be used on variable which are declared using register storage class.

Is FILE a built-in data type?
No, it is a structure defined in stdio.h.

What is reminder for 5.0 % 2?
Error, It is invalid that either of the operands for the modulus operator (%) is a real number.

How many operators are there under the category of ternary operators?
There is only one operator and is conditional operator (? : ).

Which key word is used to perform unconditional branching?
goto

What is a pointer to a function? Give the general syntax for the same.
A pointer holding the reference of the function is called pointer to a function. In general it is declared as follows.

T (*fun_ptr) (T1,T2…); Where T is any date type.

Once fun_ptr refers a function the same can be invoked using the pointer as follows.

fun_ptr(); [Or] (*fun_ptr)();

Explain the use of comma operator (,).
Comma operator can be used to separate two or more expressions.

printf(“hi”) , printf(“Hello”);

What is a NULL statement?
A null statement is no executable statements such as ; (semicolon).

int count = 0; while( ++count<=10 ) ;

Above does nothing 10 times.

What is a static function?
A function’s definition prefixed with static keyword is called as a static function. You would make a function static if it should be called only within the same source code.

Which compiler switch to be used for compiling the programs using math library with gcc compiler?

Opiton –lm to be used as > gcc –lm <file.c>

使用math.h中聲明的庫函數(shù)還有一點(diǎn)特殊之處,gcc命令行必須加-lm選項(xiàng),因?yàn)閿?shù)學(xué)函數(shù)位于libm.so庫文件中(這些庫文件通常位于/lib目錄下),-lm選項(xiàng)告訴編譯器,我們程序中用到的數(shù)學(xué)函數(shù)要到這個(gè)庫文件里找。

Which operator is used to continue the definition of macro in the next line?
Backward slash () is used.

#define MESSAGE "Hi, \ Welcome to C"

Which operator is used to receive the variable number of arguments for a function?
Ellipses (…) is used for the same. A general function definition looks as follows

void f(int k,) { }

What is the problem with the following coding snippet?

char *s1 = "hello",*s2 = "welcome"; strcat(s1,s2);

s1 points to a string constant and cannot be altered.

Which built-in library function can be used to re-size the allocated dynamic memory?
realloc().

Define an array.
Array is collection of similar data items under a common name.

What are enumerations?
Enumerations are list of integer constants with name. Enumerators are defined with the keyword enum.

Which built-in function can be used to move the file pointer internally?

fseek() int fseek(FILE *stream, long offset, int fromwhere);

函數(shù)設(shè)置文件指針stream的位置。
如果執(zhí)行成功,stream將指向以fromwhere為基準(zhǔn),偏移offset(指針偏移量)個(gè)字節(jié)的位置,函數(shù)返回0。如果執(zhí)行失敗(比如offset取值大于等于210241024*1024,即long的正數(shù)范圍2G),則不改變stream指向的位置,函數(shù)返回一個(gè)非0值。
fseek函數(shù)和lseek函數(shù)類似,但lseek返回的是一個(gè)off_t數(shù)值,而fseek返回的是一個(gè)整型。

What is a variable?
A variable is the name storage.

Who designed C programming language?
Dennis M Ritchie.

C is successor of which programming language?
B

What is the full form of ANSI?
American National Standards Institute.

Which operator can be used to determine the size of a data type or variable?
sizeof

Can we assign a float variable to a long integer variable?
Yes, with loss of fractional part.

Is 068 a valid octal number?
No, it contains invalid octal digits.

What it the return value of a relational operator if it returns any?
Return a value 1 if the relation between the expressions is true, else 0.

How does bitwise operator XOR works.
If both the corresponding bits are same it gives 0 else 1.

What is an infinite loop?
A loop executing repeatedly as the loop-expression always evaluates to true such as

while(0 == 0) { }

Can variables belonging to different scope have same name? If so show an example.
Variables belonging to different scope can have same name as in the following code snippet.

int var; void f() { int var; } main() { int var; }

What is the default value of local and global variables?
Local variables get garbage value and global variables get a value 0 by default.

Can a pointer access the array?
Pointer by holding array’s base address can access the array.

What are valid operations on pointers?
The only two permitted operations on pointers are: i) Comparision ii) Addition/Substraction (excluding void pointers)

What is a string length?
It is the count of character excluding the ‘\0’ character.

What is the built-in function to append one string to another?
strcat() form the header string.h

Which operator can be used to access union elements if union variable is a pointer variable?
Arrow (->) operator.

Explain about ‘stdin’.
stdin in a pointer variable which is by default opened for standard input device.

Name a function which can be used to close the file stream.
fclose().

What is the purpose of #undef preprocessor?
It be used to undefine an existing macro definition.

Define a structure.
A structure can be defined of collection of heterogeneous data items.

Name the predefined macro which be used to determine whether your compiler is ANSI standard or not?
__STDC__

What is typecasting?
Typecasting is a way to convert a variable/constant from one type to another type.

What is recursion?
Function calling itself is called as recursion.

Which function can be used to release the dynamic allocated memory?
free().

What is the first string in the argument vector w.r.t command line arguments?
Program name.

How can we determine whether a file is successfully opened or not using fopen() function?
On failure fopen() returns NULL, otherwise opened successfully.

What is the output file generated by the linker.
Linker generates the executable file.

What is the maximum length of an identifier?
Ideally it is 32 characters and also implementation dependent.

What is the default function call method?
By default the functions are called by value.

Functions must and should be declared. Comment on this.
Function declaration is optional if the same is invoked after its definition.

When the macros gets expanded?
At the time of preprocessing.

Can a function return multiple values to the caller using return reserved word?
No, only one value can be returned to the caller.

What is a constant pointer?
A pointer which is not allowed to be altered to hold another address after it is holding one.

To make pointer generic for which date type it need to be declared?
Void

Can the structure variable be initialized as soon as it is declared?
Yes, w.r.t the order of structure elements only.

Is there a way to compare two structure variables?
There is no such. We need to compare element by element of the structure variables.

Which built-in library function can be used to match a patter from the string?

Strstr() char *strstr(const char *haystack, const char *needle)

參數(shù)
haystack – 要被檢索的 C 字符串。
needle – 在 haystack 字符串內(nèi)要搜索的小字符串。
返回值
該函數(shù)返回在 haystack 中第一次出現(xiàn) needle 字符串的位置,如果未找到則返回 null。

What is difference between far and near pointers?
In first place they are non-standard keywords. A near pointer can access only 2^15 memory space and far pointer can access 2^32 memory space. Both the keywords are implementation specific and are non-standard.

Can we nest comments in a C code?
No, we cannot.

Which control loop is recommended if you have to execute set of statements for fixed number of times?
for – Loop.

What is a constant?
A value which cannot be modified is called so. Such variables are qualified with the keyword const.

Can we use just the tag name of structures to declare the variables for the same?
No, we need to use both the keyword ‘struct’ and the tag name.

Can the main() function left empty?
Yes, possibly the program doing nothing.

Can one function call another?
Yes, any user defined function can call any function.

Apart from Dennis Ritchie who the other person who contributed in design of C language.
Brain Kernighan

總結(jié)

以上是生活随笔為你收集整理的C语言试题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日本午夜网站 | 99视频在线精品 | www.黄色网址.com | 极品美女被c | 91porny丨首页入口在线 | 麻豆国产尤物av尤物在线观看 | 欧美一级在线视频 | 亚洲va韩国va欧美va | 男人的天堂av女优 | 亚洲免费观看在线 | 欧美日韩少妇精品 | 一区二区精品久久 | 欧美另类tv | 麻豆午夜 | av毛片精品 | 亚洲免费福利 | 欧美污视频在线观看 | 亚洲av无码一区二区三区dv | 亚洲最新色图 | 欧美一级片在线观看 | 国产清纯在线 | gav久久| 欧美电影一区 | 成人视品 | 午夜精彩视频 | 天堂成人| 黄网站在线播放 | 黄色在线免费视频 | 亚洲国产精品成人无码区 | 91本色 | 国产精品久久久久久久久久辛辛 | 国产做爰xxxⅹ性视频国 | 黄网av | 成人毛片一区二区三区 | 91porn九色 | 日本一区二区三区在线观看 | 亚洲天堂五码 | 免费av日韩| 调教驯服丰满美艳麻麻在线视频 | 男女在线免费观看 | 欧美香蕉视频 | 国产免费一区二区三区免费视频 | 成人免费黄色网 | 好色婷婷| 久久这里只有精品23 | www午夜视频| 成年人在线免费观看视频网站 | 午夜av一区二区三区 | 91资源在线播放 | 日本熟妇人妻xxxxx | 国产精品毛片久久久久久久 | 十大污视频 | 假日游船| 亚洲香蕉一区 | www.超碰97 | 日本精品一区视频 | 亚洲欧洲日韩综合 | 国产精品3p视频 | 久久av一区二区三区漫画 | 精品在线视频观看 | 国产午夜性春猛交ⅹxxx | 美女诱惑一区二区 | 超碰男人天堂 | 久久亚洲AV成人无码一二三 | av在线播放网址 | 91视频三区 | 日日不卡av | 又粗又猛又爽又黄的视频 | 国产又粗又猛又黄又爽无遮挡 | 精品久久无码中文字幕 | 老司机深夜福利网站 | av大片免费在线观看 | 国产喷潮 | av中文资源 | 免费看片网站91 | 欧美一区二区在线视频观看 | 天堂在线中文字幕 | 亚洲首页| 黑人精品一区二区三区不 | 色老头免费视频 | 91日日夜夜 | av资源天堂| japanese强行粗暴 | 好吊视频一二三区 | 久久久成人免费视频 | 日韩av电影在线播放 | 国产精品日日做人人爱 | 久久久久久无码午夜精品直播 | 夜夜嗨av色一区二区不卡 | 韩国精品视频 | 女人扒开腿让男人捅爽 | 在线免费观看国产精品 | 国产永久免费视频 | 天天干夜夜怕 | 亚洲国产精品系列 | 亚洲一区二区三区91 | 日本大奶视频 | 伊人久久大香线蕉成人综合网 | 91国内揄拍国内精品对白 |