{"id":22623082,"url":"https://github.com/mrkem598/c-interview-q-a","last_synced_at":"2025-08-17T10:10:48.261Z","repository":{"id":78434107,"uuid":"100951857","full_name":"mrkem598/C-interview-q-a","owner":"mrkem598","description":":question::white_check_mark:An interview questions for C language! Computer algorithm and design!","archived":false,"fork":false,"pushed_at":"2017-10-10T01:37:27.000Z","size":20,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-11T17:17:04.850Z","etag":null,"topics":["c","c-language","computer-algorithms","interview","question-answering"],"latest_commit_sha":null,"homepage":"https://mrkem598.github.io/C-interview-q-a/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrkem598.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-21T12:48:42.000Z","updated_at":"2022-04-19T17:31:21.000Z","dependencies_parsed_at":"2023-07-13T00:00:19.808Z","dependency_job_id":null,"html_url":"https://github.com/mrkem598/C-interview-q-a","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mrkem598/C-interview-q-a","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrkem598%2FC-interview-q-a","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrkem598%2FC-interview-q-a/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrkem598%2FC-interview-q-a/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrkem598%2FC-interview-q-a/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrkem598","download_url":"https://codeload.github.com/mrkem598/C-interview-q-a/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrkem598%2FC-interview-q-a/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270833054,"owners_count":24653671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-language","computer-algorithms","interview","question-answering"],"created_at":"2024-12-08T23:42:13.494Z","updated_at":"2025-08-17T10:10:48.235Z","avatar_url":"https://github.com/mrkem598.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"***\n# C Language Interview Questions and Answer\n***\n\n\n***\n### This interview questions for C language is in it's infantile stage and any contribution is welcome!\n\u003cbr\u003e:school::blue_book::book:Do not expect advanced content here since I am doing this while I am learning it!!!\n\n\n***\n## 1. What does `#include\u003cstdio.h\u003e` represent in c lan?\n\nAnswer: It is a statment which tells the compiler to insert the contents of `stdio(standard input out put)` at the particular place. This is a pre-processor directive. It is not part of our program, it is an instruction to the compiler to make it do something.\nIt is the pre-processor that is part of the compiler which actually gets your program from the file.\nIt tells the compiler to inlcude the contents of a file, in this case the system file `stdio.h`.\n\n***\n## 2. `\u003c \u003e` means in `\u003cstdio.h\u003e`?\n\nAnswer: The compiler knows it's a system file and therefor must be looked for in a special place, by the fact that the name is enclosed in `\u003c \u003e`.\n\n***\n## 3. `stdio` means?\n\nAnswer: It stands for standard input output because\n               \u003cbr\u003e :white_check_mark:`printf()` is a Standard Output function.\n               \u003cbr\u003e :white_check_mark:`scanf()` is a Standard Input function.\n       In short, if we want to use `printf()` in a programme then , we need to include `stdio` header file.\n***\n## 4. If I want to use `getch()`, `clrscr()` etc.. what do I need to include in the header file?\n\nAnswer: We need to include `conio` in a header file and similarly if we are using square root function `sqrt()` we need to include `math` in a header file. \n\n***\n## 5. Write a function in C language to generate a prime numbers below 100?\n\nAnswer:\n\n```\n\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n\nmain(){\n  int this_number, divisor, not_prime;\n  \n  this_number = 3;\n  \n  while(this_number \u003c 100){\n    divisor = this_number / 2;\n    not_prime = 0;\n    while(divisor \u003e 1) {\n      if(this_number % divisor == 0) {\n              not_prime = 1;\n              divisor = 0;\n      }\n      else\n              divisor = divisor-1;\n    }\n    \n    if(not_prime == 0)\n            printf(\"%d is a prime number\\n\", this_number);\n            this_number = this_number + 1;\n  }\n  exit(EXIT_SUCCESS);\n}\n```\n\n```\nAnswer:\n3 is a prime number\n5 is a prime number\n7 is a prime number\n11 is a prime number\n13 is a prime number\n17 is a prime number\n19 is a prime number\n23 is a prime number\n29 is a prime number\n31 is a prime number\n37 is a prime number\n41 is a prime number\n43 is a prime number\n47 is a prime number\n53 is a prime number\n59 is a prime number\n61 is a prime number\n67 is a prime number\n71 is a prime number\n73 is a prime number\n79 is a prime number\n83 is a prime number\n89 is a prime number\n97 is a prime number\n```\n***\n## 6.  write a program that prints prime pairs — a pair of prime numbers that differ by 2, for example 11 and 13, 29 and 31?\n\nAnswer:\n```\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n\nmain(){\n   int this_number, divisor, not_prime;\n   int last_prime;\n\n   this_number = 3;\n   last_prime = 3;\n\n   printf(\"1, 3 is a prime pair\\n\");\n\n   while(this_number \u003c 100){\n      divisor = this_number / 2;\n      not_prime = 0;\n      while(divisor \u003e 1){\n         if(this_number % divisor == 0){\n            not_prime = 1;\n            divisor = 0;\n         }\n         else\n            divisor = divisor-1;\n      }\n\n      if(not_prime == 0){\n         if(this_number == last_prime+2)\n            printf(\"%d, %d is a prime pair\\n\",\n               last_prime, this_number);\n         last_prime = this_number;\n      }\n      this_number = this_number + 1;\n   }\n   exit(EXIT_SUCCESS);\n}\n```\n```\n1, 3 is a prime pair\n3, 5 is a prime pair\n5, 7 is a prime pair\n11, 13 is a prime pair\n17, 19 is a prime pair\n29, 31 is a prime pair\n41, 43 is a prime pair\n59, 61 is a prime pair\n71, 73 is a prime pair\n   \n ```\n***\n## 7. How to add comment in C language?\n\nAnswer: We can add comment by using /*..........*/ in C language.\n\n***\n## 8. Write variable naming rules?\n\nAnswer:\n- name can be any combination of upper and lower case letters(a-z, A-Z), digits(0-9), and the character _ No other characters can be used in a variable name.\n- name must start with a letter\n- blanks are not allowed\n- Upper and lower case are allowed e.g. NUMBER , Number, number, nuMBER are all different.\n- should be descriptive (name need to describe the the information that the variable holds)\n- no restriction on the length of variables but make it short and precise\n- names cannot be reserved words e.g float, this,...\n\n          acceptable e.g. a, b, c, C, SUM, sum, Count, value, Number, x_dot, Salary, Value1, dhgfhL\n          not acceptable e.g. 1ab\n                                             inte rest\n                                             Ca$h\n                                             Amount-of-loan (- not allowed)\n                                             int (reserved word)\n***\n## 9. OR is a binary operator and is denoted bu the symbol ||, which is two adjacent pipe symbols. What does `(x || y)` mean?\n\nAnswer: The possible output for `(x || Y)` is gonna be true or y is true or both are true.\n\n***\n## 10. Why is termination an important characteristic of an algorithm?\n\nAnswer:\n\nIf we started following an algorithm that did not terminate, we would never finish executing it!\n\n***\n## 11. Why is clarity an important characteristic of an algorithm?\n\nAnswer:\n\nWhile executing a step, we should know exactly what must be done. If we did not, then there would be no single specific outcome for a particular step. Another good reason is that algorithms are usually translated into computer programs, and computer programs do not leave room for ambiguity.\n***\n## 12. Give one example of a variable of each of the following data types:\n\nintegers\nfloating numbers\ncharacters\nBooleans\nAnswer:\nThese answers are representative of each of the data types.\n\nintegers: number of windows in a room, number of words in a memory, or the rounded-off value of the temperature (negative numbers are integers too), and so on\nfloating numbers: the cost of an item in a store, the precise temperature, and so on\ncharacters: the four directions specified by 'N', 'S', 'E', or 'W', one's letter grade in a class, or gender ('F' or 'M')\nBooleans: the answer to the questions, \"Are you female?\" or \"Do you wish to contribute to the XYZ fund?\"\n\n***\n## 13. Evaluate the results of the following expressions, given the following values for these variables:\n\n      x = true, y = true, z = false\n\n      x \u0026\u0026 y || z\n      !x \u0026\u0026 y || z\n  ```    \n  Answer:\n  a. true. This expression is interpreted as\n(x \u0026\u0026 y) || z\n\n(true \u0026\u0026 true) || false\n\n(true) || false\n\ntrue\n```\n```\nb. false. This expression is interpreted as\n((!x) \u0026\u0026 y) || z\n\n((!true) \u0026\u0026 true) || false\n\n(false \u0026\u0026 true) || false\n\nfalse || false\n\nfalse\n```\n***\n## 14. Evaluate the results of the following expressions, given the following initial values:\n```\n     x = 23, y = –10, z = 12\n\nA. x % z\nB. x + y*z\nC. x/y*z\nD. z % z\n```\nAnswer: \n```\nA. 11\n\nx % z\n23 % 12\n23/12 = 1 with a remainder of 11\n```\n```\nB. –97 \n\nThe expression is interpreted as\n\nx + (y * z)\n23 + (–10 x 12)\n23 + (–120)\n–97\n```\nC. –27.6\n\nx / y * z\n23/–10 x 12       (remember that / and * are left associative)\n–2.3 x 12\n–27.6\n```\nD. 0\nz % z\n12 % 12\n12/12 = 1 with a remainder of 0\n```\n***\n## 15. Starting with the following initial values, specify the value of each variable at the end of each step, in the following pseudocode.\n```\nx = 10, y = 20, z = 30\nSet x = x + 20 \nSet y = y * x \nSet y = y % z + x \nSet z = z – 20 \nSet z = z ^ 3 ^ 2\n```\n\tAnswer:\n  \n ![answer](https://user-images.githubusercontent.com/23619819/29866063-395e19ac-8d45-11e7-912b-59312339a18b.JPG)\n\n***\n## 16. Determine the total number of bits in a memory whose size is specified as 100MB X 32.\n\nAnswer\n\nRemember that \"B\" stands for \"byte\" (8 bits). So,\n\n100 MB = 100 * 220 * 8 bits \n              = 100 * 1,048,576 * 8 bits\n\nThus the 100 MB X 32 memory will contain 100 * 1,048,576 * 8 * 32 or 26,843,545,600 bits.\n***\n## 17. When a variable has just been declared, what initial value does it contain?\n\nAnswer:\n\nNo proper initial value exists. Using an uninitialized variable will invariably lead to run-time errors.\n***\n## 18. What is the difference between: (a) x == y and (b) x = y?\n\nAnswer:\n\nThe first, x == y, is a Boolean expression whose answer is always either true or false, whereas the second, x = y, is an assignment statement.\n***\n## 19. What is the difference between an expression and a statement?\n\nAnswer:\n\nA statement is the basic unit of execution in a program.\n\nExpressions are usually parts of statements. An expression is something that evaluates to a single valu\n\n\n\t\n\tint num1, num2, sum;\n\tsum = num1 + num2;\n\t\n\tprintf(\"\\nEnter two number : \");\n\t\n\tscanf(\"%d %d\", num1,num2);\n\t\n\tsum = num1 + num2;\n\tprintf(\"Sum : \" sum);\n\t\n\treturn(o)\n\t\n}\n\n\n***\n## 21. Write a C program to find area and circumference of a circle?\n\nAnswer:\n```\n#include\u003cstdio.h\u003e\n\nint main() {\n\n\tint rad;\n\tfloat PI = 3.14, area, ci;\n\t\n\tprintf(\"\\nEnter your radius : \");\n\tscanf(\"%d\", \u0026rad);\n\t\n\tarea = PI * rad * rad;\n\tprintf(\"\\nArea of the circle is : %f \", area);\n\t\n\tci = 2 * PI * rad;\n\tprintf(\"\\nCircumference : %f \", ci);\n\treturn 0;\n}\n```\n\n***\n## 22. Create a program that can add up the number of coins(penny, nickle, dime, quarter);\nAnswer:\n\n #include\u003cstdio.h\u003e\n   int main() {\n    /*variable defination*/\n    int penny, nickle, dime, quarter;\n    float coinTotal;\n    /*prompt for input*/\n    printf(\"\\nEnter the number of penny : \");\n    scanf(\"%d\", \u0026penny);\n    printf(\"\\nEnter the number of nickle you have : \");\n    scanf(\"%d\", \u0026nickle);\n    printf(\"\\nEnter the number of dime you have : \");\n    scanf(\"%d\", \u0026dime);\n    printf(\"\\nEnter the number of quarter you have : \");\n    scanf(\"%d\", \u0026quarter);\n    /*formula to add coin*/\n    coinTotal = (penny * 0.01) + (nickle * 0.50) + (dime * 0.10) + (quarter * 0.25);\n    /*print out the total*/\n    printf(\"\\nThe total coint you entered is : %f\", coinTotal);\n    return 0;\n  }\n\n\u003cimg width=\"737\" alt=\"screen shot 2017-09-06 at 8 44 21 pm\" src=\"https://user-images.githubusercontent.com/23619819/30140685-5212536e-9344-11e7-9fbb-eed94392889e.png\"\u003e\n\n## 22. Calculate the perimeter of the triangle? And explain your program in detail? \n\nAnswer: \nI have written, the C code for calculating the perimeter of the triangle as follow. I have used float point to inter the sides of the triangle and the base. The perimeter will be a float number.\n\n![image](https://user-images.githubusercontent.com/23619819/30174977-ea483280-93ca-11e7-821e-3c077929d1a7.png)\n\n\n***\n## 23. What is this line of code doing? scanf(“%f”, \u0026height);\n\nAnswer:The scanf get value from stdin and put in variables named. This line of code is where we can input the height from the user. The letter f stands for inputting a float number and if we want to input integers we can simply change it to %d.\n\n***\n## 23. Write a program to calculate the gross salary of a person?\n\nAnswer:\n```\n#include\u003cstdio.h\u003e\nint main() {\n\tint gross_salary, basic, da, ta;\n\t\n\tprintf(\"Enter basic salary : \");\n\tscanf(\"%d\", \u0026basic);\n\t\n\tda = (10 * basic) / 100;\n\tta = (12 * basic) /100;\n\t\n\tgross_salary = basic + da + ta;\n\t\n\tprintf(\"\\nGross salary : %d\", gross_salary);\n\treturn 0;\n}\n```\n***\n## 24. Using C program add two numbers, namely num1 and num2 to print out the result?\nAnswer:\n\n\u003cimg width=\"523\" alt=\"screen shot 2017-09-10 at 8 34 26 pm\" src=\"https://user-images.githubusercontent.com/23619819/3                    \n***\n## Create a C program to Enter a number to see if it is an even or odd number?\nAnswer:\n```\n#include \u003cstdio.h\u003e\nint main () {\n        int num;\n        printf(\"\\nEnter a number to see if it is even or odd number? : \");\n        \n        scanf(\"%d\", \u0026num);\n        \n        if(num %2 == 0)\n          printf(\"%d is an even number.\", num);\n          \n       else printf(\"%d is an odd number.\", num);\n        \n        return (0);\n}\n```\n***\n## 25. Write a C code to add 10 numbers and if the vlaue greater than 100 say it's greater than 100.\n\nAnswer:\n```\n/*The following is the C Code that will compile in execute in the online compilers.*/\n/* C code\n This program will calculate the sum of 10 integers.\n Developer: Mohammed Kemal\n Date: Sep 14, 2017 */\n#include \u003cstdio.h\u003e\nint main () {\n    /* variable definition: */\n      int value1,value2,value3,value4,value5,value6, value7,value8, value9,value10, sum;\n      /* Initialize sum */\n      sum = 0;\n      printf(\"Enter an Integer for value1\\n\");\n      scanf(\"%d\", \u0026value1);\n      printf(\"Enter an Integer for value2\\n\");\n      scanf(\"%d\", \u0026value2);\n      printf(\"Enter an Integer for value3\\n\");\n      scanf(\"%d\", \u0026value3);\n      printf(\"Enter an Integer for value4\\n\");\n      scanf(\"%d\", \u0026value4);\n      printf(\"Enter an Integer for value5\\n\");\n      scanf(\"%d\", \u0026value5);\n      printf(\"Enter an Integer for value6\\n\");\n      scanf(\"%d\", \u0026value6);\n      printf(\"Enter an Integer for value7\\n\");\n      scanf(\"%d\", \u0026value7);\n      printf(\"Enter an Integer for value8\\n\");\n      scanf(\"%d\", \u0026value8);\n      printf(\"Enter an Integer for value9\\n\");\n      scanf(\"%d\", \u0026value9);\n      printf(\"Enter an Integer for value10\\n\");\n      scanf(\"%d\", \u0026value10);\n      sum = value1 + value2 + value3 + value4 + value5 + value6 + value7 + value8 + value9 + value10;\n      printf(\"Sum is %d\\n \" , sum );\n      \n      if (sum \u003e100)\n            printf(\"Sum is over 100\\n\");\n  return 0;\n}\n\n```\n***\n## 26. Create a program to determin wheter you can drive or not by entering your age??\n\nSolution:\n```\n// C code\n// This program will ask your age and determin to drive nor not.\n// Developer: Mohammed Kemal\n// Date: Sep 24, 2017\n#include \u003cstdio.h\u003e\nint main(){\n        //declaring variable\n        int age;\n        //prompt the user to enter age\n        printf(\"\\nEnter your age to determin whether you can drive or not?\");\n        while (scanf(\"%d\", \u0026age) !=EOF) {\n        // when the age below the cut point let them know they are to Young  \n          if( age  \u003c 16 \u0026\u0026 age \u003e 0) \n          {\n            printf(\"\\nToo Young To Drive Car!\");\n        // Otherwise let them know too old to drive or too young\n          }\n          else if( age \u003e 80)\n          {\n            printf(\"\\nToo old to drive car!\");\n          }\n          else if (age \u003c 0 )\n          {\n            printf(\"\\nYou need to enter positive number!\");\n          }\n          else\n          {\n            printf(\"\\nYou can drive!\");\n          }\n            printf(\"Enter another age, or CTRL Z to exit.\\n\\n\");\n      } \n    return 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrkem598%2Fc-interview-q-a","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrkem598%2Fc-interview-q-a","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrkem598%2Fc-interview-q-a/lists"}