You are on page 1of 5

Q-Fibonacci Series in C without Q-C Program to Multiply Two 3 X 3 Matrices Q-Static Function Q-following pattern :

recursion #include<stdio.h> In C, functions are global by default. The “static” 1


#include<stdio.h> int main(){ keyword before a function 12
int main(){ int A[10][10], B[10][10],C[10][10]; name makes it static. For example, below 123
int n1=0,n2=1,n3,i,number; int i, j, k; function fun() is static#include <stdio.h> 1234
printf("Enter the number of elements:"); printf("\n Enter the First Matrix elements : #include <conio.h> #include <stdio.h>
scanf("%d",&number); \n"); // Read 1st Matrix void ref(){ int main() {
printf("\n%d %d",n1,n2);//printing 0 and 1 for (i = 1; i <= 3; i++){ static int a=1, b=11; int i, j, rows;
for(i=2;i<number;++i) for (j = 1; j <= 3; j++){ printf("%d %d\n",a,b); printf("Enter the number of rows: ");
{ scanf("%d", &A[i][j]); a++; scanf("%d", &rows);
n3=n1+n2; }} b++; for (i = 1; i <= rows; ++i) {
printf(" %d",n3); printf("\n Enter the Second Matrix elements } for (j = 1; j <= i; ++j) {
n1=n2; : \n"); // Read 2nd Matrix int main(){ printf("%d ", j);
n2=n3; for (i = 1; i <= 3; i++){ int i; }
} for (j = 1; j <= 3; j++){ for(i=1; i<3; i++){ printf("\n");
return 0; scanf("%d", &B[i][j]); ref(); }
} Output;- Enter the number of elements:15 }} }} return 0;
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 printf("\n The First Matrix : \n\n"); // Print 1st Q-What is Auto storage class? }
Q-Fibonacci Series using recursion in C Matrix Auto is a storage class/ keyword in C Programming Q- following pattern :
#include<stdio.h> for (i = 1; i <= 3; i++){ language which is used to declare a local variable. A
void printFibonacci(int n){ for (j = 1; j <= 3; j++){ A local variable is a variable which is accessed BB
static int n1=0,n2=1,n3; printf("\t %d ", A[i][j]); only within a function, memory is allocated to the CCC
if(n>0){ } variable automatically on entering the function and DDDD
n3 = n1 + n2; printf("\n"); is freed on leaving the function.#include <stdio.h> EEEEE
n1 = n2; } #include <conio.h> #include <stdio.h>
n2 = n3; printf("\n The Second Matrix : \n\n"); // Print void ref(){ int main() {
printf("%d ",n3); 2nd Matrix auto int a=1, b=11; int i, j;
printFibonacci(n-1); for (i = 1; i <= 3; i++){ printf("%d %d\n",a,b); char input, alphabet = 'A';
}} for (j = 1; j <= 3; j++){ a++; printf("Enter an uppercase character you want to
int main(){ printf("\t %d ", B[i][j]); b++; print in the last row: ");
int n; } } scanf("%c", &input);
printf("Enter the number of elements: "); printf("\n"); int main(){ for (i = 1; i <= (input - 'A' + 1); ++i) {
scanf("%d",&n); } int i; for (j = 1; j <= i; ++j) {
printf("Fibonacci Series: "); // . . . The two matrices have been multipled here . for(i=1; i<3; i++){ printf("%c ", alphabet);
printf("%d %d ",0,1); .. ref(); }
printFibonacci(n-2);//n- for (i = 1; i <= 3; i++){ }} ++alphabet;
2 because 2 numbers are already printed for (j = 1; j <= 3; j++){ Q-What is register keyword? printf("\n");
return 0; C[i][j] = 0; The register keyword is a request to the compiler }
} for (k = 1; k <= 3; k++){ that the specified variable is to be stored in a return 0;
Output:- Enter the number of elements:15 C[i][j] = C[i][j]+ A[i][k] * B[k][j]; register of the processor instead of memory as a }
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 }}} way to gain speed, mostly because it will be Q-Using file handling concept, write a C
// . . . Product of the given two Matrices is heavily used. program to read a file and count the no. of lines
Q- function to find square root of a given displayed in Matrix form . . . #include <stdio.h> in
number. printf("\n\n The Resultant of Matrix #include <conio.h> #include <stdio.h>
#include <stdio.h> Multiplication is \n\n"); int main(){ int main() {
#include <math.h> for (i = 1; i <= 3; i++){ register int a=3; FILE* file = fopen("file.txt", "r");
int main(){ for (j = 1; j <= 3; j++){ printf("%u",&a); char line[256];
double num, root; printf("\t%d", C[i][j]); } int i = 0;
printf("Enter a number: "); } Q-what is Global variables? while (fgets(line, sizeof(line), file)) {
scanf("%lf", &num); printf("\n"); Global variables are defined outside a function, i++;
root = pow(num, 0.5); } usually on top of the program. Global variables if(i == 9 )
printf("The Square Root of %.2lf is %.2lf.", num, return (0); hold their values throughout the lifetime of your {
root); } program and they can be accessed inside any of printf("%s", line);
return 0; the functions defined for the program. } }
} #include <stdio.h> fclose(file);
Output:-Enter a number: 49 #include <conio.h> return 0;
The Square Root of 49.00 is 7.00. #define value 30 }
int main(){
printf("%d",value);
return 0; }
Q-Write a C program to calculate the income tax variables of the called function. Q12) structure and a union. Q- if...else Statement
for 5 employee With this method, using addresses we would have Struct #include <stdio.h>
#include <Stdio.h> an access to the actual variables and hence we The struct keyword is used to define a structure. int main() {
#include <conio.h> would be able to manipulate them. The variables are declared in a structure, the int number;
#define MIN_INCOME1 150001 Call By Value compiler allocates memory to each variables printf("Enter an integer: ");
#define MAX_INCOME1 300000 # include <stdio.h> member. The size of a structure is equal or greater scanf("%d", &number);
#define TAX_RATE1 0.10 void swapv ( int x, int y ) ; to the sum of the sizes of each data member. if (number%2 == 0) {
#define MIN_INCOME2 300001 int main( ){ Changing the value of a member will not affect printf("%d is an even integer.",number);
#define MAX_INCOME2 500000 int a = 10, b = 20 ; other variables members. }
#define TAX_RATE2 0.20 swapv ( a, b ) ; Each variable member will be assessed at a time. else {
#define MIN_INCOME3 500001 printf ( "a = %d b = %d\n", a, b ) ; We can initialize multiple variables of a structure at printf("%d is an odd integer.",number);
#define TAX_RATE3 0.30 return 0 ; a time. }
main() { } All variable members store some value at any point return 0;
double income, deparment, taxable_income,tax; void swapv ( int x, int y ) { in the program. }
clrscr (); int t ; The structure allows initializing multiple variable Output
printf("\n Enter the income: "); t=x; members at once. Enter an integer: 7
scanf ("%lf", &income) x=y; It is used to store different data type values. 7 is an odd integer.
printf("\n Enter the deparment: "); y=t; It allows accessing and retrieving any data member Q- if statement
scanf ("%lf", &deparment) ; printf ( "x = %d y = %d\n", x, y ) ; at a time. #include <stdio.h>
taxable_income = income - 150000; } Union int main() {
if(taxable_income <= 0) { The output of the above program would be: The union keyword is used to define union. int number;
printf ("\n NO TAX"); x = 20 y = 10 The variable is declared in the union, the compiler printf("Enter an integer: ");
} a = 10 b = 20 allocates memory to the largest size variable scanf("%d", &number);
else if(taxable_income >= MIN_INCOME1 && Call by reference member. The size of a union is equal to the size of // true if number is less than 0
taxable_income < MAX_INCOME1) { # include <stdio.h> its largest data member size. if (number < 0) {
tax = (taxable_income - MIN_INCOME1) void swapr ( int *, int * ) ; Variables members share the memory space of the printf("You entered %d.\n", number);
*TAX_RATE1; int main( ){ largest size variable. }
} int a = 10, b = 20 ; Changing the value of one member will also affect printf("The if statement is easy.");
else if(taxable_income >= MIN_INCOME2 && swapr ( &a, &b ) ; other variables members. return 0;
taxable_income < MAX_INCOME2) { printf ( "a = %d b = %d\n", a, b ) ; Only one variable member will be assessed at a }
tax = (taxable_income - MIN_INCOME2) * return 0 ; time. Output:- Enter an integer: -2
TAX_RATE2; } In union, only the first data member can be You entered -2.
} void swapr ( int *x, int *y ){ initialized. Q- Else if ladder
else { int t ; Exactly only one data member stores a value at any // C program to illustrate nested-if statement
tax = (taxable_income - MIN_INCOME3) * t = *x ; particular instance in the program. #include <stdio.h>
TAX_RATE3; *x = *y ; Union allows initializing only one variable member int main(){
printf("\n TAX= %lf", tax); *y = t ; at once. int i = 20;
} } It is used for storing one at a time from different if (i == 10)
getch(); The output of the above program would be: data type values. printf("i is 10");
return 0; } a = 20 b = 10 It allows accessing and retrieving any one data else if (i == 15)
Q-Difference between Call by Value and Call by Q- Highest marks obtained by student(s) in "C member at a time. printf("i is 15");
Reference programming" in a batch of 10 students. #include <stdio.h> else if (i == 20)
Call By Value #include<stdio.h> union unionJob { printf("i is 20");
While calling a function, we pass values of struct student{ //defining a union Else
variables to it. Such functions are known as “Call int sub1; char name[32]; printf("i is not present");
By Values”. int sub2; float salary; return 0;
In this method, the value of each variable in calling int sub3; int workerNo; }
function is copied into corresponding dummy }; } uJob;
variables of the called function. void main(){ struct structJob {
With this method, the changes made to the struct student s[10]; char name[32];
dummy variables in the called function have no int i,total=0; float salary;
effect on the values of actual variables in the clrscr(); int workerNo;
calling function. for(i=0;i<=2;i++){ } sJob;
Call By Reference printf("\nEnter Marks in Three Subjects = "); int main() {
While calling a function, instead of passing the scanf("%d%d%d",& printf("size of union = %d bytes", sizeof(uJob));
values of variables, we pass address of s[i].sub1,&s[i].sub2,&s[i].sub3); printf("\nsize of structure = %d bytes",
variables(location of variables) to the function total=s[i].sub1+s[i].sub2+s[i].sub3; sizeof(sJob));
known as “Call By References. printf("\nTotal marks of s[%d] Student= %d",i,total); return 0;
In this method, the address of actual variables in } }
the calling function are copied into the dummy getch(); }
Q- Difference between break and continue Q- switch statement to perform the Q- Array of pointers to strings to read Q- rewind()
statement following arithmetic operations on two name of your five friends and display them. The rewind() function sets the file pointer at
Break Statement variables : (i) Add (ii) Subtract (iii) #include <String.h> the beginning of the stream. It is useful if you
The Break statement is used to exit from Multiplication (iv) Division #include <stdio.h> have to use stream many times.
the loop constructs. #include <stdio.h> int main() { #include<stdio.h>
The break statement is usually used with int main() { char *names[] = {"tree", "bowl", "hat", #include<conio.h>
the switch statement, and it can also use it char op; "mice", "toon"}; void main(){
double first, second; char *temp; // temporary variable for swaping FILE *fp;
within the while loop, do-while loop, or the
printf("Enter an operator (+, -, *, /): "); the values char c;
for-loop.
scanf("%c", &op); int i, j, a; clrscr();
When a break statement is encountered fp=fopen("file.txt","r");
printf("Enter two operands: "); printf("The names are:\n");
then the control is exited from the loop for (i = 0; i < 5; i++) while((c=fgetc(fp))!=EOF){
scanf("%lf %lf", &first, &second);
construct immediately. printf("%s\n", names[i]); printf("%c",c);
switch (op) {
// break statement case '+': for (i = 0; i < 5; i++) { }
#include <stdio.h> printf("%.1lf + %.1lf = %.1lf", first, second, first for (j = i + 1; j < 5; j++) { rewind(fp);//moves the file pointer at
int main() + second); a = strcmp(names[i], names[j]); beginning of the file
{ break; if (a > 0) { while((c=fgetc(fp))!=EOF){
int i = 0, j = 0; case '-': temp = names[i]; printf("%c",c);
for (int i = 0; i < 5; i++) printf("%.1lf - %.1lf = %.1lf", first, second, first names[i] = names[j]; }
{ - second); names[j] = temp; fclose(fp);
printf("i = %d, j = ", i); break; } } } getch();
for (int j = 0; j < 5; j++) case '*': printf("The arranged names are:\n"); }
{ printf("%.1lf * %.1lf = %.1lf", first, second, first for (i = 0; i < 5; i++) Q- ftell()
if (j == 2) * second); printf("%s\n", names[i]); The ftell() function returns the current file
break; return 0; position of the specified stream. We can use
break;
case '/': } ftell() function to get the total size of a file
printf("%d ", j);
printf("%.1lf / %.1lf = %.1lf", first, second, first Q- C program to calculate simple interest after moving file pointer at the end of file. We
} can use SEEK_END constant to move the file
/ second); (SI).
printf("\n"); pointer at the end of file.
break; #include <stdio.h>
} default: int main() #include <stdio.h>
return 0; printf("Error! operator is not correct"); { #include <conio.h>
} } float principle, time, rate, SI; void main (){
Continue Statement return 0; printf("Enter principle (amount): "); FILE *fp;
The continue statement is not used to exit } scanf("%f", &principle); int length;
from the loop constructs. Q- whether a given string is a palindrone or printf("Enter time: "); clrscr();
The continue statement is not used with the not. scanf("%f", &time); fp = fopen("file.txt", "r");
switch statement, but it can be used within the #include <stdio.h> printf("Enter rate: "); fseek(fp, 0, SEEK_END);
while loop, do-while loop, or for-loop. #include <string.h> scanf("%f", &rate); length = ftell(fp);
When the continue statement is encountered void isPalindrome(char str[]){ SI = (principle * time * rate) / 100; fclose(fp);
then the control automatically passed from int l = 0; printf("Simple Interest = %f", SI); printf("Size of file: %d bytes", length);
the beginning of the loop statement. int h = strlen(str) - 1; return 0; getch();
// continue statement while (h > l) } }
#include <stdio.h> { Output:-Enter principle (amount): 1200 Q- fwrite( )
int main() if (str[l++] != str[h--]) Enter time: 2 The C library function size_t fwrite(const void
{ { Enter rate: 5.4 *ptr, size_t size, size_t nmemb, FILE
int i = 0, j = 0; printf("%s is not a palindrome\n", Simple Interest = 129.600006 *stream) writes data from the array pointed to,
for (int i = 0; i < 5; i++) str); Q- fseek() by ptr to the given stream.
{ return; The fseek() function is used to set the file #include<stdio.h>
printf("i = %d, j = ", i); } } pointer to the specified offset. It is used to int main () {
for (int j = 0; j < 5; j++) printf("%s is a palindrome\n", write data into file at desired location. FILE *fp;
{ str); #include <stdio.h> char str[] = "This is tutorialspoint.com";
if (j == 2) } void main(){ fp = fopen( "file.txt" , "w" );
continue; int main(){ FILE *fp; fwrite(str , 1 , sizeof(str) , fp );
printf("%d ", j); isPalindrome("abba"); fp = fopen("myfile.txt","w+"); fclose(fp);
} isPalindrome("abbccbba"); fputs("This is javatpoint", fp); return(0);
printf("\n"); isPalindrome("geeks"); fseek( fp, 7, SEEK_SET ); }
} return 0; fputs("sonoo jaiswal", fp);
return 0; } fclose(fp);
} }
Q- Dynamic Memory Allocation in C using “realloc” or “re-allocation” method in C is Q-goto statement char str2[15];
malloc(), calloc(), free() and realloc() used to dynamically change the memory The goto statement is known as jump strcpy(str1, "tutorialspoint");
C is a structured language, it has some fixed allocation of a previously allocated memory. statement in C. As the name suggests, goto is strcpy(str2, "compileonline");
rules for programming. One of them includes In other words, if the memory previously used to transfer the program control to a puts(str1);
changing the size of an array. An array is a allocated with the help of malloc or calloc is predefined label. The goto statment can be puts(str2);
collection of items stored at contiguous insufficient, realloc can be used used to repeat some part of the code for a return(0);
memory locations. to dynamically re-allocate memory. re- particular condition. It can also be used to }
As it can be seen that the length (size) of the allocation of memory maintains the already break the multiple loops which can't be done Q-Recursion in C
array above made is 9. But what if there is a present value and new blocks will be by using a single break statement. However, Recursion is the process which comes into
requirement to change this length (size). For initialized with the default garbage value. using goto is avoided these days since it existence when a function calls a copy of
Example, Syntax: ptr = realloc(ptr, newSize); makes the program less readable and itself to work on a smaller problem. Any
If there is a situation where only 5 elements Q-Difference between operators and complecated. function which calls itself is called recursive
are needed to be entered in this array. In this operands #include <stdio.h> function, and such function calls are called
case, the remaining 4 indices are just Operators are the foundation of any int main() recursive calls. Recursion involves several
wasting memory in this array. So there is a programming language. We can define { numbers of recursive calls. However, it is
requirement to lessen the length (size) of the operators as symbols that help us to perform int num,i=1; important to impose a termination condition
array from 9 to 5. specific mathematical and logical printf("Enter the number whose table you of recursion. Recursion code is shorter than
Take another situation. In this, there is an computations on operands. want to print?"); iterative code however it is difficult to
array of 9 elements with all 9 indices filled. An arithmetic operator is a mathematical scanf("%d",&num); understand.
But there is a need to enter 3 more elements function that takes two operands and table: Recursion cannot be applied to all the
in this array. In this case, 3 indices more are performs a calculation on them. They are used printf("%d x %d = %d\n",num,i,num*i); problem, but it is more useful for the tasks
required. So the length (size) of the array in common arithmetic and most computer i++; that can be defined in terms of similar
needs to be changed from 9 to 12. languages contain a set of such operators if(i<=10) subtasks. For Example, recursion may be
This procedure is referred to as Dynamic that can be used within equations to perform goto table; applied to sorting, searching, and traversal
Memory Allocation in C. a number of types of sequential calculation. } problems.
Therefore, C Dynamic Memory Allocation can Basic arithmetic operators include: Q-C gets() function Generally, iterative solutions are more
be defined as a procedure in which the size Addition (+) The gets() function enables the user to enter efficient than recursion since function call is
of a data structure (like Array) is changed Subtraction (-) some characters followed by the enter key. All always overhead. Any problem that can be
during the runtime. Multiplication (×) the characters entered by the user get stored solved recursively, can also be solved
C provides some functions to achieve these Division (÷) in a character array. The null character is iteratively. However, some problems are best
tasks. There are 4 library functions provided Relational Operators are the operators used to added to the array to make it a string. The suited to be solved by the recursion, for
by C defined under <stdlib.h> header file to create a relationship and compare the values gets() allows the user to enter the space- example, tower of Hanoi, Fibonacci series,
facilitate dynamic memory allocation in C of two operands. separated strings. It returns the string entered factorial finding, etc.
programming. They are: For example, there are two numbers, 5 and 15, by the user. Q-A variable is nothing but a name given to a
(1)malloc(), (2)calloc(), (3)realloc() and we can get the greatest number using the #include <stdio.h> storage area that our programs can
Let’s look at each of them in greater detail. greater than operator (>) that returns 15 as the int main () { manipulate. Each variable in C has a specific
C malloc() method greatest or larger number to the 5. char str[50]; type, which determines the size and layout of
The “malloc” or “memory allocation” method Types of Relational Operators printf("Enter a string : "); the variable's memory; the range of values
in C is used to dynamically allocate a single Following are the various types of relational gets(str); that can be stored within that memory; and
large block of memory with the specified operators in C. printf("You entered: %s", str); the set of operations that can be applied to
size. It returns a pointer of type void which Equal To Operator (==) return(0); the variable.
can be cast into a pointer of any form. It It is used to compare both operands and } The name of a variable can be composed of
doesn’t Initialize memory at execution time returns 1 if both are equal or the same, and 0 Q-C puts() function letters, digits, and the underscore character. It
so that it has initialized each block with the represents the operands that are not equal. The puts() function is very much similar to must begin with either a letter or an
default garbage value initially. Logical operators printf() function. The puts() function is used to underscore. Upper and lowercase letters are
Syntax: ptr = (cast-type*) malloc(byte-size) There are four logical operators in JavaScript: print the string on the console which is distinct because C is case-sensitive. Based on
C calloc() method || (OR), && (AND), ! (NOT), ?? (Nullish previously read by using gets() or scanf() the basic types explained in the previous
“calloc” or “contiguous allocation” method Coalescing). Here we cover the first three. function. The puts() function returns an chapter, there will be the following basic
in C is used to dynamically Although they are called “logical”, they can be integer value representing the number of variable types − Constants refer to fixed
allocate the specified number of blocks of applied to values of any type, not only characters being printed on the console. values that the program may not alter during
memory of the specified type. it is very much boolean. Their result can also be of any type. Since, it prints an additional newline character its execution. These fixed values are also
similar to malloc() but has two different || (OR) with the string, which moves the cursor to the called literals.
points and these are: The “OR” operator is represented with two new line on the console, the integer value Constants can be of any of the basic data
It initializes each block with a default value vertical line symbols: returned by puts() will always be equal to the types like an integer constant, a floating
‘0’. result = a || b; number of characters present in the string constant, a character constant, or a string
It has two parameters or arguments as In classical programming, the logical OR is plus 1. literal. There are enumeration constants as
compare to malloc(). meant to manipulate boolean values only. If #include <stdio.h> well.
Syntax: ptr = (cast-type*)calloc(n, element- any of its arguments are true, it returns true, #include <string.h> Constants are treated just like regular
size); otherwise it returns false. int main () { variables except that their values cannot be
C realloc() method char str1[15]; modified after their definition.
Q-Arrays a kind of data structure that can There are the following advantages of C Q-type casting ---Converting one datatype into
store a fixed-size sequential collection of functions. another is known as type casting or, type-
elements of the same type. An array is used to By using functions, we can avoid rewriting conversion. For example, if you want to store
store a collection of data, but it is often more same logic/code again and again in a a 'long' value into a simple integer then you
useful to think of an array as a collection of program. can type cast 'long' to 'int'. You can convert
variables of the same type. We can call C functions any number of times the values from one type to another explicitly
Instead of declaring individual variables, such in a program and from any place in a program. using the cast operator as follows −
as number0, number1, ..., and number99, you We can track a large C program easily when it (type_name) expression
declare one array variable such as numbers is divided into multiple functions. #include <stdio.h>
and use numbers[0], numbers[1], and ..., Reusability is the main achievement of C main() {
numbers[99] to represent individual variables. functions. int sum = 17, count = 5;
A specific element in an array is accessed by However, Function calling is always a double mean;
an index. overhead in a C program. mean = (double) sum / count;
All arrays consist of contiguous memory Function Aspects printf("Value of mean : %f\n", mean );
locations. The lowest address corresponds to There are three aspects of a C function. }
the first element and the highest address to Function declaration A function must be Q-run time --Programming is basically solving
the last element. declared globally in a c program to tell the a particular problem by giving coded
Q-A pointer to a pointer is a form of multiple compiler about the function name, function instructions to the computer. Furthermore, the
indirection, or a chain of pointers. Normally, a parameters, and return type. whole scenario of the programming cycle
pointer contains the address of a variable. Function call Function can be called from involves writing, testing, troubleshooting,
When we define a pointer to a pointer, the first anywhere in the program. The parameter list debugging, and maintaining a computer
pointer contains the address of the second must not differ in function calling and function program. Moreover, a good program should
pointer, which points to the location that declaration. We must pass the same number have clarity and simplicity of expressions,
contains the actual value as shown below. of functions as it is declared in the function should make use of the proper name of
A variable that is a pointer to a pointer must declaration. identifiers, contain comments, and have a
be declared as such. This is done by placing Function definition It contains the actual proper indentation. Besides, it should be free
an additional asterisk in front of its name. For statements which are to be executed. It is the from all types of errors such as syntax errors,
example, the following declaration declares a most important aspect to which the control runtime errors, and logical errors.
pointer to a pointer of type int −int comes when the function is called. Here, we Q-logical error-Programming is basically
**var;include <stdio.h> must notice that only one value can be solving a particular problem by giving coded
int main () { returned from the function. instructions to the computer. Furthermore, the
int var; SN C function aspects Syntax whole scenario of the programming cycle
int *ptr; 1 Function declaration return_type involves writing, testing, troubleshooting,
int **pptr; function_name (argument list); debugging, and maintaining a computer
var = 3000; 2 Function call function_name program. Moreover, a good program should
/* take the address of var */ (argument_list) have clarity and simplicity of expressions,
ptr = &var; 3 Function definition return_type should make use of the proper name of
/* take the address of ptr using address of function_name (argument list) {function identifiers, contain comments, and have a
operator & */ body;} proper indentation. Besides, it should be free
pptr = &ptr; Q-pointer --The pointer in C language is a from all types of errors such as syntax errors,
/* take the value using pptr */ variable which stores the address of another runtime errors, and logical errors.
printf("Value of var = %d\n", var ); variable. This variable can be of type int, char, Q-C Strings-The string can be defined as the
printf("Value available at *ptr = %d\n", *ptr ); array, function, or any other pointer. The size one-dimensional array of characters
printf("Value available at **pptr = %d\n", of the pointer depends on the architecture. terminated by a null ('\0'). The character array
**pptr); However, in 32-bit architecture the size of a or the string is used to manipulate text such
return 0; pointer is 2 byte. int n = 10; as word or sentences. Each character in the
} int* p = &n; // Variable p of type pointer is array occupies one byte of memory, and the
Q-In c, we can divide a large program into the pointing to the address of the variable n of last character must always be 0. The
basic building blocks known as function. The type integer. termination character ('\0') is important in a
function contains the set of programming Declaring a pointer string since it is the only way to identify where
statements enclosed by {}. A function can be The pointer in c language can be declared the string ends. When we define a string as
called multiple times to provide reusability using * (asterisk symbol). It is also known as char s[10], the character s[10] is implicitly
and modularity to the C program. In other indirection pointer used to dereference a initialized with the null in the memory.
words, we can say that the collection of pointer. There are two ways to declare a string in c
functions creates a program. The function is int *a;//pointer to int language.
also known as procedure or subroutine in char *c;//pointer to char By char array By string literal
other programming languages. Let's see the example of declaring string by
Advantage of functions in C char array in C language.
char ch[10]={'j', 'a', 'v', 'a', 't', 'p', 'o', 'i', 'n', 't',
'\0'};

You might also like