SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 1
1)what is function?
Ans:
A function is a group of statements that together perform a task. Every C program has at least one function, which is
main(), and all the most trivial programs can define additional functions.
2)what is pointer?
Ans:
Pointer is a user defined data type which creates special types of variables which can hold the address of primitive data
type like char, int, float, double or user defined data type like function, pointer etc. or derived data type like array, structure,
union, enum.
3)what is array?
Ans:
C programming language provides a data structure called the array, which can store a fixed-size sequential
collection of elements of the same type. An array is used to store a collection of data, but it is often more useful
to think of an array as a collection of variables of the same type.
Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array
variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual
variables. A specific element in an array is accessed by an index.
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the
highest address to the last element.
4)what is string?
Ans:
a one-dimensional array of characters which is terminated by a null character '0'. Thus a null-terminated string contains the
characters that comprise the string followed by a null.
5)what is structure?
Ans:
A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is
used to select it from the structure. A structure is a convenient way of grouping several pieces of related information together.
A structure can be defined as a new named type, thus extending the number of available types. It can use other structures,
arrays or pointers as some of its members, though this can get complicated unless you are careful.
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 2
6)what is union?
Ans:
A union is a special data type available in C that enables you to store different data types in the same memory location.
You can define a union with many members, but only one member can contain a value at any given time. Unions provide an
efficient way of using the same memory location for multi-purpose.
7)what is calloc?
Ans:
The C library function void *calloc(size_t nitems, size_t size) allocates the requested memory and returns a pointer to it.
The difference in malloc and calloc is that malloc does not set the memory to zero where as calloc sets allocated memory
to zero.
8)what is malloc?
Ans :
the library function malloc is used to allocate a block of memory on the heap. The program accesses this block of memory
via a pointer that malloc returns. When the memory is no longer needed, the pointer is passed to free which deallocates the
memory so that it can be used for other purposes.
9)what is macro?
Ans:
A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of
the macro. There are two kinds of macros
10)what is typedef?
Ans:
"C allows you to explicitly define new data type names by using the keyword typedef. You are not actually creating a new
data type, but rather defining a new name for an existing type." ^ Typedef as a Synonym, It allows you to introduce
synonyms for types which could have been declared some other way.
11)what is function prototype?
Ans:
A function prototype is basically a definition for a function. It is structured in the same way that a normal function is
structured, except instead of containing code, the prototype ends in a semicolon. Normally, the C compiler will make a
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 3
single pass over each file you compile. If it encounters a call to a function that it has not yet been defined, the compiler has
no idea what to do and throws an error.
12)difference between call by value and call by reference?
Ans:
Call by Value :If data is passed by value, the data is copied from the variable used in for example main() to a variable used
by the function. So if the data passed (that is stored in the function variable) is modified inside the function, the value is only
changed in the variable used inside the function
Call by Reference :If data is passed by reference, a pointer to the data is copied instead of the actual variable as is done in
a call by value. Because a pointer is copied, if the value at that pointers address is changed in the function, the value is also
changed in main()
13)difference between calloc and malloc?
Ans:
malloc() takes a single argument (memory required in bytes), while calloc() needs two arguments. Secondly, malloc() does
not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO. calloc() allocates a memory
area, the length will be the product of its parameters
14)difference between structure and union?
Ans:
The difference between structure and union in c are:
1. union allocates the memory equal to the maximum memory
required by the member of the union but structure allocates the memory equal to the total memory required by the
members.
2. In union, one block is used by all the member of the union but in case of structure, each member have
their own memory space .
15)difference between ++*p and *p++?
Ans:
++*p means prefix of the variable.Ex1:class {int *p=4;int *q=++*p;s.o.p(*q);}output:the value of *q is 5.*p++ means postfix
of the variable.Ex2:class{int *p=4;int *q=*p++;s.o.p(*q);}output:the value of *q is 4.Ex3:class{int i=5; int j=i++; int k=i++; int
t=i;s.o.p(t);}output:the value of j is 5the value of k is 6the value of t is 7.
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 4
16)difference between static and auto keyword?
Ans:
"automatic" means they have the storage duration of the current block, and are destroyed when leaving the block. "local"
means they have the scope of the current block, and can't be accessed from outside the block. If a local variable is static,
then it is not destroyed when leaving the block; it just becomes inaccessible until the block is reentered. See the for-loop
examples in my answer for the difference between automatic and static storage duration for local variables.
17)difference between function and macro?
Ans:
1.Macro consumes less time:
When a function is called, arguments have to be passed to it, those arguments are accepted by corresponding dummy
variables in the function. Then they are processed, and finally the function returns a value that is assigned to a variable
(except for a void function). If a function is invoked number of times, the times add up, and compilation is delayed. On the
other hand, the macro expansion had already taken place and replaced each occurrence of the macro in the source code
before the source code starts compiling, so it requires no additional time to execute.
2. Function consumes less memory:
Prior to compilation, all the macro-presences are replaced by their corresponding macro expansions, which consumes
considerable memory. On the other hand, even if a function is invoked 100 times, it still occupies the same space. Hence
function consumes less memory.
18)what is storage class in c?
Ans:
A storage class defines the scope (visibility) and life time of variables and/or functions within a C Program.
There are following storage classes which can be used in a C Program
 auto
 register
 static
 extern
auto - Storage Class
auto is the default storage class for all local variables.
register - Storage Class
register is used to define local variables that should be stored in a register instead of RAM. This means that the variable
has a maximum size equal to the register size (usually one word) and cant have the unary '&' operator applied to it (as it
does not have a memory location).
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 5
static - Storage Class
static is the default storage class for global variables. The two variables below (count and road) both have a static storage
class
extern - Storage Class
extern is used to give a reference of a global variable that is visible to ALL the program files. When you use 'extern' the
variable cannot be initalized as all it does is point the variable name at a storage location that has been previously defined
19)how to execute c program(steps)?
Ans:
Steps are :
1.Save: f2
2.Compile :alt+f9
3.Run: ctrl+f9 ,and
4.Output :alt +f5
20)what is bit wise operator’s?
Ans:
C provides a compound assignment operator for each binary arithmetic and bitwise operation (i.e. each operation which
accepts two operands). Each of the compound bitwise assignment operators perform the appropriate binary operation and
store the result in the left operand.
PROGRAMS:-
1) write a program to find weather the given year is leap year or not?
Ans:
#include <stdio.h>
int main()
{
int year;
printf("Enter a year to check if it is a leap yearn");
scanf("%d", &year);
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 6
if ( year%400 == 0)
printf("%d is a leap year.n", year);
else if ( year%100 == 0)
printf("%d is not a leap year.n", year);
else if ( year%4 == 0 )
printf("%d is a leap year.n", year);
else
printf("%d is not a leap year.n", year);
return 0;
}
2) write a program to find weather the given number is prime number or not?
Ans:
#include<stdio.h>
int main()
{
int n, i = 3, count, c;
printf("Enter the number of prime numbers requiredn");
scanf("%d",&n);
if ( n >= 1 )
{
printf("First %d prime numbers are :n",n);
printf("2n");
}
for ( count = 2 ; count <= n ; )
{
for ( c = 2 ; c <= i - 1 ; c++ )
{
if ( i%c == 0 )
break;
}
if ( c == i )
{
printf("%dn",i);
count++;
}
i++;
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 7
}
return 0;
}
3) write a program to find factorial of given number ?
Ans:
 without using recursion :
#include <stdio.h>
int main()
{
int c, n, fact = 1;
printf("Enter a number to calculate it's factorialn");
scanf("%d", &n);
for (c = 1; c <= n; c++)
fact = fact * c;
printf("Factorial of %d = %dn", n, fact);
return 0;
}
 with using recursion :
#include<stdio.h>
int factorial(int n);
int main()
{
int n;
printf("Enter an positive integer: ");
scanf("%d",&n);
printf("Factorial of %d = %ld", n, factorial(n));
return 0;
}
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 8
int factorial(int n)
{
if(n!=1)
return n*factorial(n-1);
}
4) write a program to fibonacci without using Recursion & using Recursion ?
ans:
 Fibonacci series in c using for loop
/* Fibonacci Series c language */
#include<stdio.h>
int main()
{
int n, first = 0, second = 1, next, c;
printf("Enter the number of termsn");
scanf("%d",&n);
printf("First %d terms of Fibonacci series are :-n",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%dn",next);
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 9
}
return 0;
}
 Fibonacci series program in c using recursion
#include<stdio.h>
int Fibonacci(int);
main()
{
int n, i = 0, c;
scanf("%d",&n);
printf("Fibonacci seriesn");
for ( c = 1 ; c <= n ; c++ )
{
printf("%dn", Fibonacci(i));
i++;
}
return 0;
}
int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 10
5) write a program to swap two numbers without using third variable ?
Ans:
#include <stdio.h>
void main()
{
int a,b;
printf("enter number1: ie a");
scanf("%d",a);
printf("enter number2:ie b ");
scanf("%d",b);
printf(value of a and b before swapping is a=%d,b=%d"a,b);
a=a+b;
b=a-b;
a=a-b;
printf(value of a and b after swapping is a=%d,b=%d"a,b);
}
6) write a program to reverse a given number . ?
Ans:
#include <stdio.h>
int main()
{
int n, reverse = 0;
printf("Enter a number to reversen");
scanf("%d",&n);
while (n != 0)
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 11
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
printf("Reverse of entered number is = %dn", reverse);
return 0;
}
7) write a program to reverse a given string ?
Ans:
#include <stdio.h>
#include <string.h>
int main()
{
char arr[100];
printf("Enter a string to reversen");
gets(arr);
strrev(arr);
printf("Reverse of entered string is n%sn",arr);
return 0;
}
8) write a program to check given number is palindrome or not ?
Ans:
#include <stdio.h>
#include <string.h>
int main()
{
char a[100], b[100];
printf("Enter the string to check if it is a palindromen");
gets(a);
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 12
strcpy(b,a);
strrev(b);
if( strcmp(a,b) == 0 )
printf("Entered string is a palindrome.n");
else
printf("Entered string is not a palindrome.n");
return 0;
}
9) write a program to sorting the given array by using selection sort?
Ans:
#include <stdio.h>
int main()
{
int array[100], n, c, d, position, swap;
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d integersn", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d", &array[c]);
for ( c = 0 ; c < ( n - 1 ) ; c++ )
{
position = c;
for ( d = c + 1 ; d < n ; d++ )
{
if ( array[position] > array[d] )
position = d;
}
if ( position != c )
{
swap = array[c];
array[c] = array[position];
array[position] = swap;
}
}
printf("Sorted list in ascending order:n");
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 13
for ( c = 0 ; c < n ; c++ )
printf("%dn", array[c]);
return 0;
}
10)write a program to convert a given binary number to decimal number?
Ans:
#include <stdio.h>
#include <math.h>
int binary_decimal(int n);
int decimal_binary(int n);
int main()
{
int n;
char c;
printf("Instructions:n");
printf("1. Enter alphabet 'd' to convert binary to decimal.n");
printf("2. Enter alphabet 'b' to convert decimal to binary.n");
scanf("%c",&c);
if (c =='d' || c == 'D')
{
printf("Enter a binary number: ");
scanf("%d", &n);
printf("%d in binary = %d in decimal", n, binary_decimal(n));
}
if (c =='b' || c == 'B')
{
printf("Enter a decimal number: ");
scanf("%d", &n);
printf("%d in decimal = %d in binary", n, decimal_binary(n));
}
return 0;
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 14
}
int decimal_binary(int n) /* Function to convert decimal to binary.*/
{
int rem, i=1, binary=0;
while (n!=0)
{
rem=n%2;
n/=2;
binary+=rem*i;
i*=10;
}
return binary;
}
int binary_decimal(int n) /* Function to convert binary to decimal.*/
{
int decimal=0, i=0, rem;
while (n!=0)
{
rem = n%10;
n/=10;
decimal += rem*pow(2,i);
++i;
}
return decimal;
}
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 15
11)write a program to convert a given decimal number to binary number?
Ans:
#include <stdio.h>
int main()
{
int n, c, k;
printf("Enter an integer in decimal number systemn");
scanf("%d", &n);
printf("%d in binary number system is:n", n);
for (c = 31; c >= 0; c--)
{
k = n >> c;
if (k & 1)
printf("1");
else
printf("0");
}
printf("n");
return 0;
}
Name :shiva kumar kella
Email : smileshiva1@gmail.com Page 16

Weitere ähnliche Inhalte

Was ist angesagt?

1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answersAkash Gawali
 
C interview questions
C interview questionsC interview questions
C interview questionsSoba Arjun
 
CS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2ndCS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2ndEdward Chen
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comShwetaAggarwal56
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingVijaySharma802
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments rajni kaushal
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL Rishabh-Rawat
 
Syntax Comparison of Golang with C and Java - Mindbowser
Syntax Comparison of Golang with C and Java - MindbowserSyntax Comparison of Golang with C and Java - Mindbowser
Syntax Comparison of Golang with C and Java - MindbowserMindbowser Inc
 

Was ist angesagt? (20)

C++ Interview Questions
C++ Interview QuestionsC++ Interview Questions
C++ Interview Questions
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
C interview questions
C interview questionsC interview questions
C interview questions
 
Python advance
Python advancePython advance
Python advance
 
Java execise
Java execiseJava execise
Java execise
 
Chapter 02 functions -class xii
Chapter 02   functions -class xiiChapter 02   functions -class xii
Chapter 02 functions -class xii
 
Linked list
Linked listLinked list
Linked list
 
CS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2ndCS225_Prelecture_Notes 2nd
CS225_Prelecture_Notes 2nd
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Python programming
Python  programmingPython  programming
Python programming
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
 
CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL CBSE Class 12 Computer practical Python Programs and MYSQL
CBSE Class 12 Computer practical Python Programs and MYSQL
 
Computer Science Assignment Help
 Computer Science Assignment Help  Computer Science Assignment Help
Computer Science Assignment Help
 
Pointers
PointersPointers
Pointers
 
C Programming Homework Help
C Programming Homework HelpC Programming Homework Help
C Programming Homework Help
 
Pointers
PointersPointers
Pointers
 
Syntax Comparison of Golang with C and Java - Mindbowser
Syntax Comparison of Golang with C and Java - MindbowserSyntax Comparison of Golang with C and Java - Mindbowser
Syntax Comparison of Golang with C and Java - Mindbowser
 

Ähnlich wie C basic questions&amp;ansrs by shiva kumar kella

Ähnlich wie C basic questions&amp;ansrs by shiva kumar kella (20)

C language 100 questions answers
C language 100 questions answersC language 100 questions answers
C language 100 questions answers
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
What is c language
What is c languageWhat is c language
What is c language
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
cprogramming questions for practice end term
cprogramming questions for practice end termcprogramming questions for practice end term
cprogramming questions for practice end term
 
C Programming - Refresher - Part IV
C Programming - Refresher - Part IVC Programming - Refresher - Part IV
C Programming - Refresher - Part IV
 
Tcs NQTExam technical questions
Tcs NQTExam technical questionsTcs NQTExam technical questions
Tcs NQTExam technical questions
 
C++ interview question
C++ interview questionC++ interview question
C++ interview question
 
Intervies
InterviesIntervies
Intervies
 
Technical_Interview_Questions.pdf
Technical_Interview_Questions.pdfTechnical_Interview_Questions.pdf
Technical_Interview_Questions.pdf
 
C interview question answer 1
C interview question answer 1C interview question answer 1
C interview question answer 1
 
Java Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRaoJava Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRao
 
Javainterviewquestions 110607071413-phpapp02
Javainterviewquestions 110607071413-phpapp02Javainterviewquestions 110607071413-phpapp02
Javainterviewquestions 110607071413-phpapp02
 
Javainterviewquestions 110607071413-phpapp02
Javainterviewquestions 110607071413-phpapp02Javainterviewquestions 110607071413-phpapp02
Javainterviewquestions 110607071413-phpapp02
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
interview questions.docx
interview questions.docxinterview questions.docx
interview questions.docx
 

Kürzlich hochgeladen

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 

Kürzlich hochgeladen (20)

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 

C basic questions&amp;ansrs by shiva kumar kella

  • 1. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 1 1)what is function? Ans: A function is a group of statements that together perform a task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. 2)what is pointer? Ans: Pointer is a user defined data type which creates special types of variables which can hold the address of primitive data type like char, int, float, double or user defined data type like function, pointer etc. or derived data type like array, structure, union, enum. 3)what is array? Ans: C programming language provides a data structure called the array, which can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. A specific element in an array is accessed by an index. All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. 4)what is string? Ans: a one-dimensional array of characters which is terminated by a null character '0'. Thus a null-terminated string contains the characters that comprise the string followed by a null. 5)what is structure? Ans: A structure is a collection of variables under a single name. These variables can be of different types, and each has a name which is used to select it from the structure. A structure is a convenient way of grouping several pieces of related information together. A structure can be defined as a new named type, thus extending the number of available types. It can use other structures, arrays or pointers as some of its members, though this can get complicated unless you are careful.
  • 2. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 2 6)what is union? Ans: A union is a special data type available in C that enables you to store different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multi-purpose. 7)what is calloc? Ans: The C library function void *calloc(size_t nitems, size_t size) allocates the requested memory and returns a pointer to it. The difference in malloc and calloc is that malloc does not set the memory to zero where as calloc sets allocated memory to zero. 8)what is malloc? Ans : the library function malloc is used to allocate a block of memory on the heap. The program accesses this block of memory via a pointer that malloc returns. When the memory is no longer needed, the pointer is passed to free which deallocates the memory so that it can be used for other purposes. 9)what is macro? Ans: A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros 10)what is typedef? Ans: "C allows you to explicitly define new data type names by using the keyword typedef. You are not actually creating a new data type, but rather defining a new name for an existing type." ^ Typedef as a Synonym, It allows you to introduce synonyms for types which could have been declared some other way. 11)what is function prototype? Ans: A function prototype is basically a definition for a function. It is structured in the same way that a normal function is structured, except instead of containing code, the prototype ends in a semicolon. Normally, the C compiler will make a
  • 3. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 3 single pass over each file you compile. If it encounters a call to a function that it has not yet been defined, the compiler has no idea what to do and throws an error. 12)difference between call by value and call by reference? Ans: Call by Value :If data is passed by value, the data is copied from the variable used in for example main() to a variable used by the function. So if the data passed (that is stored in the function variable) is modified inside the function, the value is only changed in the variable used inside the function Call by Reference :If data is passed by reference, a pointer to the data is copied instead of the actual variable as is done in a call by value. Because a pointer is copied, if the value at that pointers address is changed in the function, the value is also changed in main() 13)difference between calloc and malloc? Ans: malloc() takes a single argument (memory required in bytes), while calloc() needs two arguments. Secondly, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO. calloc() allocates a memory area, the length will be the product of its parameters 14)difference between structure and union? Ans: The difference between structure and union in c are: 1. union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members. 2. In union, one block is used by all the member of the union but in case of structure, each member have their own memory space . 15)difference between ++*p and *p++? Ans: ++*p means prefix of the variable.Ex1:class {int *p=4;int *q=++*p;s.o.p(*q);}output:the value of *q is 5.*p++ means postfix of the variable.Ex2:class{int *p=4;int *q=*p++;s.o.p(*q);}output:the value of *q is 4.Ex3:class{int i=5; int j=i++; int k=i++; int t=i;s.o.p(t);}output:the value of j is 5the value of k is 6the value of t is 7.
  • 4. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 4 16)difference between static and auto keyword? Ans: "automatic" means they have the storage duration of the current block, and are destroyed when leaving the block. "local" means they have the scope of the current block, and can't be accessed from outside the block. If a local variable is static, then it is not destroyed when leaving the block; it just becomes inaccessible until the block is reentered. See the for-loop examples in my answer for the difference between automatic and static storage duration for local variables. 17)difference between function and macro? Ans: 1.Macro consumes less time: When a function is called, arguments have to be passed to it, those arguments are accepted by corresponding dummy variables in the function. Then they are processed, and finally the function returns a value that is assigned to a variable (except for a void function). If a function is invoked number of times, the times add up, and compilation is delayed. On the other hand, the macro expansion had already taken place and replaced each occurrence of the macro in the source code before the source code starts compiling, so it requires no additional time to execute. 2. Function consumes less memory: Prior to compilation, all the macro-presences are replaced by their corresponding macro expansions, which consumes considerable memory. On the other hand, even if a function is invoked 100 times, it still occupies the same space. Hence function consumes less memory. 18)what is storage class in c? Ans: A storage class defines the scope (visibility) and life time of variables and/or functions within a C Program. There are following storage classes which can be used in a C Program  auto  register  static  extern auto - Storage Class auto is the default storage class for all local variables. register - Storage Class register is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size (usually one word) and cant have the unary '&' operator applied to it (as it does not have a memory location).
  • 5. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 5 static - Storage Class static is the default storage class for global variables. The two variables below (count and road) both have a static storage class extern - Storage Class extern is used to give a reference of a global variable that is visible to ALL the program files. When you use 'extern' the variable cannot be initalized as all it does is point the variable name at a storage location that has been previously defined 19)how to execute c program(steps)? Ans: Steps are : 1.Save: f2 2.Compile :alt+f9 3.Run: ctrl+f9 ,and 4.Output :alt +f5 20)what is bit wise operator’s? Ans: C provides a compound assignment operator for each binary arithmetic and bitwise operation (i.e. each operation which accepts two operands). Each of the compound bitwise assignment operators perform the appropriate binary operation and store the result in the left operand. PROGRAMS:- 1) write a program to find weather the given year is leap year or not? Ans: #include <stdio.h> int main() { int year; printf("Enter a year to check if it is a leap yearn"); scanf("%d", &year);
  • 6. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 6 if ( year%400 == 0) printf("%d is a leap year.n", year); else if ( year%100 == 0) printf("%d is not a leap year.n", year); else if ( year%4 == 0 ) printf("%d is a leap year.n", year); else printf("%d is not a leap year.n", year); return 0; } 2) write a program to find weather the given number is prime number or not? Ans: #include<stdio.h> int main() { int n, i = 3, count, c; printf("Enter the number of prime numbers requiredn"); scanf("%d",&n); if ( n >= 1 ) { printf("First %d prime numbers are :n",n); printf("2n"); } for ( count = 2 ; count <= n ; ) { for ( c = 2 ; c <= i - 1 ; c++ ) { if ( i%c == 0 ) break; } if ( c == i ) { printf("%dn",i); count++; } i++;
  • 7. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 7 } return 0; } 3) write a program to find factorial of given number ? Ans:  without using recursion : #include <stdio.h> int main() { int c, n, fact = 1; printf("Enter a number to calculate it's factorialn"); scanf("%d", &n); for (c = 1; c <= n; c++) fact = fact * c; printf("Factorial of %d = %dn", n, fact); return 0; }  with using recursion : #include<stdio.h> int factorial(int n); int main() { int n; printf("Enter an positive integer: "); scanf("%d",&n); printf("Factorial of %d = %ld", n, factorial(n)); return 0; }
  • 8. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 8 int factorial(int n) { if(n!=1) return n*factorial(n-1); } 4) write a program to fibonacci without using Recursion & using Recursion ? ans:  Fibonacci series in c using for loop /* Fibonacci Series c language */ #include<stdio.h> int main() { int n, first = 0, second = 1, next, c; printf("Enter the number of termsn"); scanf("%d",&n); printf("First %d terms of Fibonacci series are :-n",n); for ( c = 0 ; c < n ; c++ ) { if ( c <= 1 ) next = c; else { next = first + second; first = second; second = next; } printf("%dn",next);
  • 9. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 9 } return 0; }  Fibonacci series program in c using recursion #include<stdio.h> int Fibonacci(int); main() { int n, i = 0, c; scanf("%d",&n); printf("Fibonacci seriesn"); for ( c = 1 ; c <= n ; c++ ) { printf("%dn", Fibonacci(i)); i++; } return 0; } int Fibonacci(int n) { if ( n == 0 ) return 0; else if ( n == 1 ) return 1; else return ( Fibonacci(n-1) + Fibonacci(n-2) ); }
  • 10. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 10 5) write a program to swap two numbers without using third variable ? Ans: #include <stdio.h> void main() { int a,b; printf("enter number1: ie a"); scanf("%d",a); printf("enter number2:ie b "); scanf("%d",b); printf(value of a and b before swapping is a=%d,b=%d"a,b); a=a+b; b=a-b; a=a-b; printf(value of a and b after swapping is a=%d,b=%d"a,b); } 6) write a program to reverse a given number . ? Ans: #include <stdio.h> int main() { int n, reverse = 0; printf("Enter a number to reversen"); scanf("%d",&n); while (n != 0)
  • 11. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 11 { reverse = reverse * 10; reverse = reverse + n%10; n = n/10; } printf("Reverse of entered number is = %dn", reverse); return 0; } 7) write a program to reverse a given string ? Ans: #include <stdio.h> #include <string.h> int main() { char arr[100]; printf("Enter a string to reversen"); gets(arr); strrev(arr); printf("Reverse of entered string is n%sn",arr); return 0; } 8) write a program to check given number is palindrome or not ? Ans: #include <stdio.h> #include <string.h> int main() { char a[100], b[100]; printf("Enter the string to check if it is a palindromen"); gets(a);
  • 12. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 12 strcpy(b,a); strrev(b); if( strcmp(a,b) == 0 ) printf("Entered string is a palindrome.n"); else printf("Entered string is not a palindrome.n"); return 0; } 9) write a program to sorting the given array by using selection sort? Ans: #include <stdio.h> int main() { int array[100], n, c, d, position, swap; printf("Enter number of elementsn"); scanf("%d", &n); printf("Enter %d integersn", n); for ( c = 0 ; c < n ; c++ ) scanf("%d", &array[c]); for ( c = 0 ; c < ( n - 1 ) ; c++ ) { position = c; for ( d = c + 1 ; d < n ; d++ ) { if ( array[position] > array[d] ) position = d; } if ( position != c ) { swap = array[c]; array[c] = array[position]; array[position] = swap; } } printf("Sorted list in ascending order:n");
  • 13. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 13 for ( c = 0 ; c < n ; c++ ) printf("%dn", array[c]); return 0; } 10)write a program to convert a given binary number to decimal number? Ans: #include <stdio.h> #include <math.h> int binary_decimal(int n); int decimal_binary(int n); int main() { int n; char c; printf("Instructions:n"); printf("1. Enter alphabet 'd' to convert binary to decimal.n"); printf("2. Enter alphabet 'b' to convert decimal to binary.n"); scanf("%c",&c); if (c =='d' || c == 'D') { printf("Enter a binary number: "); scanf("%d", &n); printf("%d in binary = %d in decimal", n, binary_decimal(n)); } if (c =='b' || c == 'B') { printf("Enter a decimal number: "); scanf("%d", &n); printf("%d in decimal = %d in binary", n, decimal_binary(n)); } return 0;
  • 14. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 14 } int decimal_binary(int n) /* Function to convert decimal to binary.*/ { int rem, i=1, binary=0; while (n!=0) { rem=n%2; n/=2; binary+=rem*i; i*=10; } return binary; } int binary_decimal(int n) /* Function to convert binary to decimal.*/ { int decimal=0, i=0, rem; while (n!=0) { rem = n%10; n/=10; decimal += rem*pow(2,i); ++i; } return decimal; }
  • 15. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 15 11)write a program to convert a given decimal number to binary number? Ans: #include <stdio.h> int main() { int n, c, k; printf("Enter an integer in decimal number systemn"); scanf("%d", &n); printf("%d in binary number system is:n", n); for (c = 31; c >= 0; c--) { k = n >> c; if (k & 1) printf("1"); else printf("0"); } printf("n"); return 0; }
  • 16. Name :shiva kumar kella Email : smileshiva1@gmail.com Page 16