NCCS C 1st Sem Pre Board Solution

1st sem New Syllabus

1. Difference between actual and formal parameters

Actual parameters: Values/variables passed to a function when it is called
Formal parameters: Variables declared in the function definition to receive the passed values

Example:

 

2. Use of ftell() and rewind() functions

  • ftell(): Returns the current file position indicator (in bytes) of the file stream
    Example: long pos = ftell(filePtr);

  • rewind(): Sets the file position indicator to the beginning of the file
    Example: rewind(filePtr);

3. Four keywords of C

  1. int

  2. if

  3. return

  4. while
    (Other examples: charfloatforswitch)

4. NULL pointer

A pointer that doesn’t point to any memory location (value 0). Used to indicate that the pointer is not currently valid or initialized.

Example:

5. When to use -> (arrow) operator

Used to access members of a structure or union through a pointer to that structure/union.

Example:

 

6. What’s wrong with: name = "NCCS"

  • name must be a character array or pointer

  • For arrays, use strcpy(name, "NCCS")

  • For pointers, first allocate memory

Correct versions:


 

7. Can { } be used for single line of code?

Yes, curly brackets can enclose a single line, though not required. It’s good practice for consistency and future code expansion.

Example:

 

8. When “switch” is preferable over “if”

  • When testing a single variable against multiple constant values

  • For better readability with many conditions

  • When compiler can optimize with jump tables

Example:

 

9. Preprocessor with example

The preprocessor processes source code before compilation. Directives begin with #.

Example:

 

10. Bitwise operator

Operators that work on bits of integer types:

Operator Meaning Example
& AND a & b
OR a b
^ XOR a ^ b
~ NOT (flips bits) ~a
<< Left shift a << 2
>> Right shift a >> 1

Example usage:

 

11. Program to find frequency of odd & even numbers in a matrix

 

12. Program to check if first name contains only lowercase alphabets.

 

13. Program to draw a circle in C (using graphics.h)

14. Dynamic memory allocation functions

Check Notes of Your college

15. Commenting in C and debugging use

Comment types in C:

  1. Single-line: // This is a comment

  2. Multi-line: /* This is a multi-line comment */

Debugging with comments:

  • Temporarily commenting out code (instead of deleting) helps:

    • Isolate problematic sections

    • Test code incrementally

    • Preserve original code for reference

16. Algorithm to check Armstrong number

Armstrong number: A number equal to the sum of its own digits each raised to the power of the number of digits.

Algorithm:

  1. Input a number n

  2. Store original number in temp

  3. Calculate number of digits (d)

  4. Initialize sum = 0

  5. While n > 0:

    • Extract last digit (digit = n % 10)

    • Add digit^d to sum

    • Remove last digit (n = n / 10)

  6. If sum equals original number (temp)

    • Print “Armstrong number”

  7. Else

    • Print “Not Armstrong number”

17. Program to sort array in descending order using pointers

18.  Palindrome Check

19. Program to print the binary pattern

20. Program to find largest and smallest in array


21. College Name Program

Program to store and display college name:

22. Course Information Program:

 

a

 

Leave a Reply

Your email address will not be published. Required fields are marked *