C Pointers 3 - C Programming Tutorial
C Course / Miscellaneous / C Pointers 3

C Pointers 3

BLUF: Understanding C Pointers 3 is a foundational part of learning C programming. This tutorial explains the core principles and syntax needed to implement this concept effectively.
Core Programming Principle: C Pointers 3

C provides direct access to memory and system resources. Learn how C Pointers 3 leverages this power in the lesson below.

  • int main (int argc, char *argv)
  • int main { int char (*argv argc); }
  • None of the above

Explanation:

In certain scenarios, it becomes essential to provide input values through the command line to a C program to execute specific code when the program is externally controlled. These input values specified in the command line are referred to as command line arguments. The main function is responsible for managing and processing these command line arguments.

Use of main with command line argument is,

int main (int argc, char *argv)

Here, argv denotes the pointer array pointing to each argument supplied to the program, while argc represents the count of arguments passed.

12) What is the error in below C statement?

Example

signed int *p=(int*)malloc(sizeof(unsigned int));
  • Memory will be allocated but cannot hold an int value in the memory
  • Improper type casting
  • Would throw Runtime error
  • No issue with statement

Explanation:

In the provided C statement, the size of an integer and an unsigned integer is identical. Therefore, there are no issues with memory allocation.

Therefore the given C statement has no error.

13) Choose the correct option for the below program.

Example

#include<stdio.h>
main()
{
   int *a, **b;   
   printf("%u\n", sizeof(a));
   printf("%u\n", sizeof(b));
}
  • First printf prints the value less than the second
  • Second printf prints the value less than the first
  • Both the printf will print the same value
  • Error in the code

Explanation:

Each variety of pointer variable consumes an identical quantity of memory regardless of the data type it points to.

As a result, both printf statements will display identical values.

14) What will be the output of the below program?

Example

#include<stdio.h>
void main()
{
   char *a = "C++";
   printf("%s ", a);
   a++;
   printf("%s", a);
}
  • C++ ++
  • C++ C++
  • ++ ++
  • Compile error

Explanation:

The initial print function, namely printf("%s ", a), is employed to display the content stored within pointer a. Consequently, the output showcases the text "C++".

After a++, a points the string "++".

Therefore, the subsequent print function, namely printf("%s ", a);, displays the ++ in the output.

Therefore, the final result produced by the program is C++ ++.

15) In the below statement, what does the "pf" indicates?

Example

int (*pf)();
  • pf is a pointer
  • pf is a function pointer
  • pf is a pointer of function which returns int
  • None of the above

Explanation:

In the provided scenario, "pf" serves as a pointer and also stores a reference to a function.

Therefore, "pf" represents a function pointer that returns an integer.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience