Tuesday, 12 December 2017

C interview Question

What does static variable means?
Static variable is a variable which retain its value between the function calls.

They are initialized only once and their scope is within the function where they are defined.

A static variable inside a function has a lifespan as long as  program runs. It won't be allocated every time  function is called and deallocated when  function returns.

#include<stdio.h>
void function ()
{
int a=10;
static int sa=10;
a+=5;
sa+=5;
print("a=%d  sa=%d",a,sa);
}

void main()
{
int i;
for(i=0;i=<3;i++)
function ();
}

Output:
sa:15   a:15
sa:20   a:15
sa:25   a:15
sa:30   a:15

Reference:
1)https://stackoverflow.com/questions/5033627/static-variable-inside-of-a-function-in-c

2)https://youtu.be/VGovIzt-ggM

Monday, 11 December 2017

Stdio.h

Formatted input output functions
printf(): Prints formatted output.
fprintf(): Prints formatted output to a file.

scanf():Reads formatted input.
fscanf()
sscanf()

Unformatted input output functions
getc(): Reads a character.
getchar()
gets(): Reads array of characters.
fgets():
puts():Writes array of characters.
putchar():
putc(): writes a character.
fgetc(): Reads a character from file.
fputc(): Writes a character into a file.
fputs()
getw()
putw()
fgetchar()
fputchar()
fgetchar
fgetc()

File access functions
fopen(): Opens  file.
fclose(): Closes file.
fflush(): Synchronizes an output stream with the actual file.
fseek():Moves the file position indicator to a specific location in a file.
ftell():
rewind():Moves the file position indicator to the beginning in a file.
remove(): Erases a file.

Error handling functions
clearerr():Clears errors.
feof():Checks for the end-of-file.

Reference:
https://en.m.wikipedia.org/wiki/C_file_input/output#/search

Sunday, 10 December 2017

Library of C language

What is  library ?
Library is the collection of header files.

What is header file ?
Hearder file contains predefined functions

Header files
<aio.h>
<libgen.h>
<spawn.h>
<sys/time.h>
<arpa/inet.h>
<limits.h>
<stdarg.h>
<sys/times.h>
<assert.h>
<locale.h>
<stdbool.h>
<sys/types.h>
<complex.h>
<math.h>
<stddef.h>
<sys/uio.h>
<cpio.h>
<monetary.h>
<stdint.h>
<sys/un.h>
<ctype.h>
<mqueue.h>
<stdio.h>
<sys/utsname.h>
<dirent.h>
<ndbm.h>
<stdlib.h>
<sys/wait.h>
<dlfcn.h>
<net/if.h>
<string.h>
<syslog.h>
<errno.h>
<netdb.h>
<strings.h>
<tar.h>
<fcntl.h>
<netinet/in.h>
<stropts.h>
<termios.h>
<fenv.h>
<netinet/tcp.h>
<sys/ipc.h>
<tgmath.h>
<float.h>
<nl_types.h>
<sys/mman.h>
<time.h>
<fmtmsg.h>
<poll.h>
<sys/msg.h>
<trace.h>
<fnmatch.h>
<pthread.h>
<sys/resource.h>
<ulimit.h>
<ftw.h>
<pwd.h>
<sys/select.h>
<unistd.h>
<glob.h>
<regex.h>
<sys/sem.h>
<utime.h>
<grp.h>
<sched.h>
<sys/shm.h>
<utmpx.h>
<iconv.h>
<search.h>
<sys/socket.h>
<wchar.h>
<inttypes.h>
<semaphore.h>
<sys/stat.h>
<wctype.h>
<iso646.h>
<setjmp.h>
<sys/statvfs.h>
<wordexp.h>
<langinfo.h>
<signal.h>


Reference:

https://stackoverflow.com/questions/2027991/list-of-standard-header-files-in-c-and-c/

Thursday, 7 December 2017

Functions in C

Function prototype
Function defining
return_type function_name(parameter_type parameters)
{
predefined logic
return_value
}
Function Calling
function_name(arguments)

What is a function ?
Function is a set/block of instructions/predefined logic which takes arguments/parameters as input and process the input using the predefined logic and gives the desired output/return value.

What are arguments?
Arguments also know as parameters are the inputs to a function.
In specific
Arguments are the Actual values ,We use this in function calling.
Parameters are the Placeholders ,We use this in function definition.

What are return values?
Return values are the output of a function.

What are the types of functions ?
Basically Functions are divided into 4 types:
1)No arguments No return values.
2)No arguments with return values.
3)With arguments No return values
4)With arguments With return values

Wednesday, 6 December 2017

Variables in C

What is variable ?
Variable is a named memory location.
Setting identities to the memory location by which data stored can be processed easily.

Tuesday, 5 December 2017

Platform dependency of C language

Why C is platform dependent programming language?
All programming languages are platform independent, but the executable file which is being created after compiling the program is one of the main reason to become platform dependent.
Windows can only handle .exe files , similarly Mac can handle only .dmg files

Why the Compiler creates the executable file which can run in host operating system only?
C Compiler is platform dependent since it is closely linked to the OS kernel which is different for different OS.

Hope you have got the idea of platform dependency of C language.
Thank you..

Sunday, 3 December 2017

C Language

Brief History:
C programming language was developed by Dennis Ritchie in Bell Laboratory year 1972

Why the name C ?
It was named "C" because its features were derived from an earlier language called "BCPL"

What is BCPL language ?
Basic combined programming language.
BCPL - a smaller language which was good for low-level programming. Well suited for writing compilers and system code.

Who developed BCPL ?
Ken Thompson was the developer of B language.

What are applications of C language ?
Application of C is mainly divided into
1) Standalone applications: It depends on compatibility of Operating system  .
Ex: MS word ,Ms office, VLC player

2) Web application's: Independent of Operating System.
Ex: Any website which can accessible using browser's from any os.

*UNIX kernel is completely developed in C language.
*The Mars Curiosity rover is running 2.5 million lines of C on a RAD 750 processor.

Above mentioned are few applications of C language several other applications are also  possible using C.

Saturday, 2 December 2017

Programming Language

What is Language?
Language is the way of sharing information.

What is computer/machine language?
It is also a way/media of sharing information between you and the machine.

Why machine language is needed?
Lets start with a example,
What is the value of √25=5 simple, But when you need to calculate the value of √1250 it takes time , Instead of doing calculations manually we need a machine to do that , which will give answer in fractions of seconds.

How machine understands our language?
Machine understands only Binary language that is 0&1 .

How to convert  human understandable
language to binary language ?
It is  impossible to convert every instruction into machine language, Therefore Compiler will do that for you.

What is Compiler?
Compiler is a software which converts Human understandable language/High-level language into machine understandable language

Therefore to reduce complexity and save our time we have to learn a programming language through which we can give instructions we needed to perform a desired task.



C interview question 8

What will be the output of the given code? #include <stdio.h> int main(void) { float a = 3.14; printf("%f",a%3); ...