B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP Mostly Asked C Programming Questions - Basics | LiveCodeProgramming

Mostly Asked C Programming Questions – Basics (Top 10)

Q1. Features of C languageC भाषा की विशेषताएँ

C is a procedural programming language, considered middle-level because it combines features of both high-level and low-level languages. It is fast, supports pointers for direct memory manipulation, portable across platforms, and widely used for system programming like operating systems and embedded systems.

C एक प्रक्रियात्मक प्रोग्रामिंग भाषा है, जिसे मध्य-स्तरीय माना जाता है क्योंकि यह उच्च-स्तरीय और निम्न-स्तरीय दोनों भाषाओं की विशेषताओं को मिलाता है। यह तेज़ है, पॉइंटर्स का समर्थन करता है जिससे सीधे मेमोरी को नियंत्रित किया जा सकता है, विभिन्न प्लेटफार्मों पर पोर्टेबल है, और सिस्टम प्रोग्रामिंग जैसे ऑपरेटिंग सिस्टम और एम्बेडेड सिस्टम के लिए व्यापक रूप से उपयोग होती है।

Q2. Structure of a C programC प्रोग्राम की संरचना

A C program generally includes:
1. Preprocessor directives (like #include for headers).
2. main() function which is the entry point.
3. Variable declarations.
4. Statements that implement logic.
5. Return statement to end program execution.

Example:

#include <stdio.h>

int main() {
  printf("Hello, World!\n");
  return 0;
}

एक C प्रोग्राम सामान्यतः निम्नलिखित भागों में विभाजित होता है:
1. प्रीप्रोसेसर निर्देश (जैसे #include हेडर फ़ाइलों के लिए)।
2. main() फ़ंक्शन जो प्रोग्राम का प्रवेश बिंदु होता है।
3. वेरिएबल घोषणा।
4. लॉजिक को लागू करने वाले स्टेटमेंट।
5. प्रोग्राम निष्पादन समाप्त करने के लिए रिटर्न स्टेटमेंट।

उदाहरण:

#include <stdio.h>

int main() {
  printf("Hello, World!\n");
  return 0;
}

Q3. Role of main() functionmain() फ़ंक्शन की भूमिका

The main() function is the starting point of program execution. The operating system calls main() when the program starts. It returns an integer value to the OS, typically 0 means success. The signature is usually int main(void) or int main(int argc, char *argv[]) for command-line arguments.

main() फ़ंक्शन प्रोग्राम निष्पादन का आरंभिक बिंदु होता है। प्रोग्राम शुरू होने पर ऑपरेटिंग सिस्टम main() को कॉल करता है। यह एक पूर्णांक मान लौटाता है, आमतौर पर 0 का मतलब सफल निष्पादन होता है। इसका स्वरूप सामान्यतः int main(void) या कमांड-लाइन तर्कों के लिए int main(int argc, char *argv[]) होता है।

Q4. Keywords vs Identifiersकीवर्ड्स बनाम आइडेंटिफायर्स

Keywords are reserved words predefined by the C language that have special meanings and cannot be used as variable or function names, e.g., int, return, if.
Identifiers are programmer-defined names for variables, functions, arrays, etc., following naming rules (letters, digits, underscores; not starting with a digit).

Keywords वे आरक्षित शब्द होते हैं जिन्हें C भाषा पहले से परिभाषित करती है और जिनका विशेष अर्थ होता है, जैसे int, return, if। इन्हें वेरिएबल या फ़ंक्शन नाम के रूप में इस्तेमाल नहीं किया जा सकता।
Identifiers वे नाम हैं जिन्हें प्रोग्रामर वेरिएबल, फ़ंक्शन, एरे आदि के लिए बनाते हैं, जो कुछ नामकरण नियमों का पालन करते हैं (अक्षर, अंक, अंडरस्कोर; अंक से शुरू नहीं होना चाहिए)।

Q5. Difference between #include <> and #include "..."Difference between #include <> and #include "..."

#include <filename> is used to include standard library or system header files. The compiler searches in system directories.
#include "filename" is used to include user-defined header files. The compiler first searches the current directory, then system directories.

#include <filename> का उपयोग मानक लाइब्रेरी या सिस्टम हेडर फाइलों को शामिल करने के लिए किया जाता है। कंपाइलर सिस्टम डायरेक्टरी में खोज करता है।
#include "filename" का उपयोग उपयोगकर्ता द्वारा परिभाषित हेडर फाइलों को शामिल करने के लिए किया जाता है। कंपाइलर पहले वर्तमान डायरेक्टरी में खोजता है, फिर सिस्टम डायरेक्टरी में।

Q6. Data types in CC में डेटा प्रकार

Data types define the type and size of data that variables can store. Basic types include:
int for integers,
char for characters,
float for single-precision floating-point numbers,
double for double-precision floating-point numbers.
Derived types include arrays, pointers, structures.

डेटा प्रकार यह निर्धारित करते हैं कि वेरिएबल किस प्रकार और आकार का डेटा रख सकता है। बुनियादी प्रकारों में शामिल हैं:
int पूर्णांक के लिए,
char अक्षरों के लिए,
float सिंगल प्रिसिजन फ्लोटिंग-पॉइंट नंबर के लिए,
double डबल प्रिसिजन फ्लोटिंग-पॉइंट नंबर के लिए।
डेरिव्ड प्रकारों में एरे, पॉइंटर्स, स्ट्रक्चर शामिल हैं।

Q7. Difference: signed vs unsignedअंतर: signed बनाम unsigned

Signed data types can store both positive and negative values by allocating one bit for sign. Unsigned types store only non-negative values but can represent a larger positive range.
Example:
signed int x = -10;
unsigned int y = 20;

Signed डेटा प्रकार दोनों सकारात्मक और नकारात्मक मान रख सकते हैं क्योंकि एक बिट साइन के लिए रिज़र्व होता है। Unsigned प्रकार केवल गैर-नकारात्मक मान रखते हैं लेकिन वे अधिक सकारात्मक सीमा का प्रतिनिधित्व कर सकते हैं।
उदाहरण:
signed int x = -10;
unsigned int y = 20;

Q8. Size of int, char, float, doubleint, char, float, double का आकार

Typical sizes on a 32-bit system:
int – 4 bytes,
char – 1 byte,
float – 4 bytes,
double – 8 bytes.
Sizes may vary depending on system architecture and compiler.

32-बिट सिस्टम पर सामान्य आकार:
int – 4 बाइट,
char – 1 बाइट,
float – 4 बाइट,
double – 8 बाइट।
आकार सिस्टम आर्किटेक्चर और कंपाइलर पर निर्भर कर सकते हैं।

Q9. Variable declaration and initializationवेरिएबल घोषणा और प्रारंभिककरण

Declaration defines the type and name of a variable to the compiler. Initialization assigns an initial value.
Example:
int count; (declaration)
int total = 100; (declaration + initialization)

डिक्लेरेशन कंपाइलर को वेरिएबल के प्रकार और नाम बताता है। इनिशियलाइज़ेशन प्रारंभिक मान असाइन करता है।
उदाहरण:
int count; (डिक्लेरेशन)
int total = 100; (डिक्लेरेशन + इनिशियलाइज़ेशन)

Q10. Storage classes in C (auto, static, etc.)C में स्टोरेज क्लासेस (auto, static, आदि)

Storage classes specify scope, lifetime, and visibility of variables:
- auto: default local variable storage.
- static: preserves value between function calls.
- register: suggests storing in CPU register.
- extern: references global variables defined elsewhere.
Example:

void func() {
  static int count = 0;
  count++;
  printf("%d\n", count);
}

Storage classes वेरिएबल की स्कोप, जीवनकाल और दृश्यता को परिभाषित करते हैं:
- auto: डिफ़ॉल्ट लोकल वेरिएबल स्टोरेज।
- static: फ़ंक्शन कॉल के बीच मान को सुरक्षित रखता है।
- register: CPU रजिस्टर में स्टोर करने का सुझाव देता है।
- extern: कहीं और परिभाषित ग्लोबल वेरिएबल को संदर्भित करता है।
उदाहरण:

void func() {
  static int count = 0;
  count++;
  printf("%d\n", count);
}